Today i’m retrieving our Entra ID users using this code snippet:
Get-AzureADUser -All $true -Filter "UserType eq 'Member'"| Select-Object -Property $args[0] | Where-Object {($_.DirSyncEnabled -eq 'True')}
Later in my script I am using a code snippet I found on Google to retrieve licens status for each user:
Get-AzureAdUser -ObjectId $Object.ObjectId | ForEach{ $licensed=$False ; For ($i=0; $i -le ($_.AssignedLicenses | Measure).Count ; $i++)` { If( [string]::IsNullOrEmpty( $_.AssignedLicenses[$i].SkuId ) -ne $True) { $licensed='Active' } } ; If( $licensed -eq $false)` { $licensed='Inactive'} }
But I would like to retrieve all data from Azure one time so I am trying to combine these two into one query.
If I just combine the pipe I doesn’t retrieve any data. Just blank.
I was thinking of combining them both and instead of just putting the value into an variable add new psobject for each user. Like:
Get-AzureAdUser -ObjectId $Object.ObjectId | ForEach{ $licensed=$False ; For ($i=0; $i -le ($_.AssignedLicenses | Measure).Count ; $i++)` { If( [string]::IsNullOrEmpty( $_.AssignedLicenses[$i].SkuId ) -ne $True) { $Object | Add-Member -MemberType NoteProperty -Name "LicenseStatus" -Value "Active" } } ; If( $licensed -eq $false)` { $Object | Add-Member -MemberType NoteProperty -Name "LicenseStatus" -Value "Inactive" } }