Forum Discussion
How to list users synced from onprem AD and cloud-only users?
Hello guys!
I was tasked to list users synced from onprem AD and cloud only users
I have downloaded and imported AzureAD PS module 2.0.2.16
Azure portal shows several users with source 'Azure Active Directory'.
I'm first trying to list these cloud-only users by running a command command Get-AzureADUser | where {$_.dirsyncenabled -eq $false} but it yields only one user when there should be a lot more.
I also need to list users synced from onprem AD.
My command does not seem to do the trick. Can you help me out?
Teijo Hämäläinen I would try following Get-MsolUser -All | ?{-not $_.lastdirsynctime}
- ved-leachimBrass Contributor
I would recommend using the AzureAD PowerShell Module. You can use the following command to get a list of all Cloud Only Accounts:
Get-AzureADUser -All $true | Where-Object {$_.ImmutableId -eq $null}
If you want a list with the Cloud Only Accounts without guests, you could use the following command:
Get-AzureADUser -All $true | Where-Object {$_.ImmutableId -eq $null -and $_.UserPrincipalName -notlike "*#EXT#*"}
- Martin RublikBrass Contributor
Teijo Hämäläinen I would try following Get-MsolUser -All | ?{-not $_.lastdirsynctime}
There's also Get-MsolUser -Synchronized. Using the server-side filtering is faster approach, and also makes sure you don't get a trimmed list because of hitting the limit for number of objects returned (like when you have the Get-AzureADUser cmdlet above, without the -All switch, and filtering client-side).
- Martin RublikBrass Contributor
thanks, definitely a better solution.
Martin
- Teijo HämäläinenCopper Contributor
- David_RichardBrass Contributor
You need to use the new Microsoft Graph PowerShell SDK to retrieve this information.
The below article has a script that will export that information and much more:
https://www.alitajran.com/export-azure-ad-users-to-csv-powershell/