Microsoft Office 365 User accounts are stored in Azure Active Directory. In a hybrid environment, user accounts and passwords from an on-premises AD DS domain can be synchronized to Azure AD using Azure AD Connect. In this environment, the Azure AD user accounts will either be cloud-only identities, or synced identities.
We can use the Get-AzureADUser cmdlet to retrieve the list of users and apply a filter with the property DirSyncEnabled to find a list of synced and non-synced identities. Before proceeding, install the Azure AD PowerShell V2 module and run the below command to connect Azure AD PowerShell.
Connect-AzureAD
Find list of users synced from On-Premises AD
Run the following command to retrieve all Azure AD users that are synced from AD.
Get-AzureADUser -All $true | Where-Object {$_.DirSyncEnabled -eq $true}
You can easily select required properties such as UserPrincipalName, LastDirSyncTime (Directory Sync Status) and export the result to a CSV file.
Get-AzureADUser -All $true | Where-Object {$_.DirSyncEnabled -eq $true} | `
Select-Object DisplayName,UserPrincipalName,LastDirSyncTime | `
Export-CSV "C:\SyncedUsers.CSV" -NoTypeInformation -Encoding UTF8
List cloud-only users
Run the following command to retrieve a list of cloud-only users (or non-synced users).
Get-AzureADUser -All $true | Where-Object {$_.DirSyncEnabled -eq $null}
Find synchronized users with MSOnline Powershell module
Alternatively, we can use the Get-MsolUser cmdlet to list synchronized users. The below command retrieves the list of users that are synced from On-Premises AD.
Get-MsolUser -All | Where-Object {$_.ImmutableId -ne $null}
Run the following command to get cloud-only users.
Get-MsolUser -All | Where-Object {$_.ImmutableId -eq $null}
Get-AzureADUser by default only returns the first 100 entries. If you have more than 100 users, you need to include the -All switch. So the command to find cloud only accounts is Get-AzureADUser -All $true | Where-Object {$_.DirSyncEnabled -eq $null}
Thanks. Updated the same in the post.
Hi,
I was wondering if someone could help please.
I need to get a list of all Ad synced users plus I need to find which on prem domain those users are connected to
I have tried the below so far but no luck.
I need basically a lot of information in the export, ProxAddresses, UPN, Display Name, Mailbox Type, Immutable ID, Extension Attribute 15, Distinguished name, Account enabled, Sam Account name, On premises domain name, On-premises user principal name
Any help would be really appreciated.