Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

seems get-mtuser count argument is not working as intended as object returns more than count limited #626

Open
heetehub opened this issue Jan 17, 2025 · 3 comments

Comments

@heetehub
Copy link

I seems the count break should be in foreach otherwise has no effect.

foreach ( $EntraIDRole in $EntraIDRoles ) {
$TmpUsers = Invoke-MtGraphRequest -RelativeUri "directoryRoles/$($EntraIDRole.id)/members" -Select id, userPrincipalName, userType -OutputType Hashtable
if ( $TmpUsers.ContainsKey('userType') ) {
Write-Verbose "Setting userType to Admin for $($TmpUsers.Count) users that are member of $($EntraIDRole.displayName)."
$TmpUsers | ForEach-Object {
$.userType = "Admin"
$Users.Add($
) | Out-Null
# I put count check in loop
if ($Users.Count -ge $Count) {
Write-Verbose "Found $Count $UserType users."
break
}
}
<#
if ($Users.Count -ge $Count) {
Write-Verbose "Found $Count $UserType users."
break
}
#>

@heetehub heetehub changed the title get-mtuser count not working as intended as object return more than count get-mtuser count not working as intended as object return more than count and produces an object with more users than asked for Jan 17, 2025
@heetehub heetehub changed the title get-mtuser count not working as intended as object return more than count and produces an object with more users than asked for seems get-mtuser count argument is not working as intended as object returns more than count limited Jan 17, 2025
@weyCC81
Copy link
Contributor

weyCC81 commented Jan 17, 2025

  • Which Test or File are you referring to?

if ($Users.Count -ge $Count) {

if ($Users.Count -ge $Count) {

if ($Users.Count -ge $Count) {

It is just happening for Admin and BreakGlass/EmergencyAccess correct?

Get-MtUser -Count 5 -UserType Member # 5 > OK
Get-MtUser -Count 2 -UserType Member -Verbose; $test1.Count # 2  > OK
Get-MtUser -Count 1 -UserType Member -Verbose; $test1.Count # 1 > OK

Get-MtUser -Count 2 -UserType Admin -Verbose; $test2.Count # 18 > NOK
# VERBOSE: Setting userType to Admin for 18 users that are member of Global Administrator.
# VERBOSE: Found 5 Member users.
Get-MtUser -Count 1 -UserType Admin -Verbose; $test2.Count # 18  > NOK

@heetehub
Copy link
Author

Which Test or File are you referring to?

Get-MtUser.ps1 line 85, 120, 136,

@heetehub
Copy link
Author

Yes correct, as far as I see the issue presents itself only for admin and bg accounts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants