Skip to content
Menu
Tech Automation Blog
  • About Author
  • Contact
Tech Automation Blog

List all Azure AD users

Posted on August 18, 2019February 27, 2022

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
Connect to Azure AD Account

After you login to Azure, run the powershell script saved in previous step.

Run Powershell script

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on LinkedIn (Opens in new window) LinkedIn
June 2025
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« May    

Recent Posts

  • Monitor and alert Azure Service Health issues May 5, 2020
  • AWS IAM User access review May 3, 2020
  • Integrate Azure Security Center with Event Hub April 28, 2020
  • Add Tags to Azure Subscription April 24, 2020
  • Automate Azure billing report in Excel March 6, 2020

Categories

©2025 Tech Automation Blog | Powered by SuperbThemes