Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arjancornelissen/a832d587a2363949f45c33eef40d1480 to your computer and use it in GitHub Desktop.
Save arjancornelissen/a832d587a2363949f45c33eef40d1480 to your computer and use it in GitHub Desktop.
Enhanced where-object on large datalist
$msolusers = Get-MsolUser -All | Select-object ObjectId, WhenCreated, LastPasswordChangeTimestamp, @{n="mfaenabled";e={$_.StrongAuthenticationMethods.Count -gt 0}}
$users = Get-AzureADUser -All $true | Select-Object ObjectId, UserPrincipalName, DisplayName, @{n="onpremDN";e={$_.ExtensionProperty.onPremisesDistinguishedName}}, CompanyName, AccountEnabled, UserType
# Create empty array and do a foreach on every item, this takes a few seconds on 30.000 items
$msoluserArray = @{}
$i=0
$msolusers.foreach({
$msoluserArray["$($psitem.ObjectId)"] = $i
$i++
})
foreach($user in $users)
{
$msoluser = $msolusers[($msoluserArray[$user.ObjectId])]
# do something with this data
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment