In this post, I am going to share Powershell commands to find the list of disabled or sign-in blocked Azure AD users and export them to CSV. We can use the Azure AD Powershell command Get-AzureADUser to get user details, this command includes the property AccountEnabled which indicates the user account status.
Before proceed, install Azure Active Directory PowerShell for Graph module and run the below command to connect Azure AD PowerShell module:
Connect-AzureAD
The below command checks the given user account is enabled or disabled.
$user = "[email protected]" $accountEnabled = (Get-AzureADUser -ObjectId $user).AccountEnabled If ($accountEnabled) { Write-Host "$user : account enabled" -foreground Green } Else { Write-Host "$user : account disabled" -foreground Red }
Find and List All Disabled Office 365 Users:
Get-AzureADUser -All $True | Where-Object { $_.AccountEnabled -eq $false}
Export Disabled Users to CSV file:
Get-AzureADUser -All $True | Where-Object { $_.AccountEnabled -eq $false} | Select-Object UserPrincipalName, DisplayName | Export-CSV "C:\DisabledO365Users.csv" -NoTypeInformation -Encoding UTF8
Advertisement