Here is a Powershell script to generate a report on Azure Active Directory Users in Azure tenant. This csv file report with information of all Azure AD users. It includes a list of all standard properties you need to know for a user. You can refer Microsoft Documentation for more details.
Again, I run this script just to have a quick and easy report of Azure AD to present to my management or auditors.
Let me know if this is helpful!
If you want to get details of Azure AD group details. Refer my post here.
$currentDir = $(Get-Location).Path
$oFile = "$($currentDir)\AzureADUsers_Details.csv"
if(Test-Path $oFile){Remove-Item $oFile -Force}
"DisplayName,upNUserPrincipalNameme,ObjectId,DeletionTimestamp,AccountEnabled,AssignedLicenses,AssignedPlans,DirSyncEnabled,LastDirSyncTime,OnPremisesSecurityIdentifier,PasswordPolicies,RefreshTokensValidFromDateTime,UserType,ADObjectPath" | Out-File $oFile -Append -Encoding ASCII
Get-AzureADUser -All $true | ForEach-Object{
$DisplayName = $upNUserPrincipalNameme = $ObjectId = $DeletionTimestamp = $AccountEnabled = $AssignedLicenses = $AssignedPlans = $DirSyncEnabled = ""
$LastDirSyncTime = $OnPremisesSecurityIdentifier = $PasswordPolicies = $RefreshTokensValidFromDateTime = $UserType = $ADObjectPath = ""
$DisplayName = $_.DisplayName.split(",")[0]
$upNUserPrincipalNameme = $_.UserPrincipalName
$ObjectId = $_.ObjectId
$DeletionTimestamp = $_.DeletionTimestamp
$AccountEnabled = $_.AccountEnabled
$AssignedLicenses = ""
$AssignedPlans = ""
$DirSyncEnabled = $_.DirSyncEnabled
$LastDirSyncTime = $_.LastDirSyncTime
$OnPremisesSecurityIdentifier = $_.OnPremisesSecurityIdentifier
$PasswordPolicies = $_.PasswordPolicies
$RefreshTokensValidFromDateTime = $_.RefreshTokensValidFromDateTime
$UserType = $_.UserType
if(!([String]::IsNullOrEmpty($OnPremisesSecurityIdentifier))){
$ADObjectPath = (Get-ADUser -Filter {SID -eq $OnPremisesSecurityIdentifier} -Properties DistinguishedName | select DistinguishedName -ExpandProperty DistinguishedName )
if(!([String]::IsNullOrEmpty($ADObjectPath))){
$ADObjectPath = $ADObjectPath.Replace(","," ")
}
} "$DisplayName,$upNUserPrincipalNameme,$ObjectId,$DeletionTimestamp,$AccountEnabled,$AssignedLicenses,$AssignedPlans,$DirSyncEnabled,$LastDirSyncTime,$OnPremisesSecurityIdentifier,$PasswordPolicies,$RefreshTokensValidFromDateTime,$UserType,$ADObjectPath" | Out-File $oFile -Append -Encoding ASCII
}
Download above script and save it with a .ps1 file extension. Open powershell console and, connect to your Azure AD account using – Connect-AzureAD. It will prompt you to enter your Azure credentials.
![This image has an empty alt attribute; its file name is image-6.png](https://i0.wp.com/arindamhazra.com/wp-content/uploads/2019/08/image-6.png?w=640)
After you login to Azure, run the powershell script saved in previous step.
![](https://i0.wp.com/arindamhazra.com/wp-content/uploads/2019/08/image-7.png?resize=640%2C122)