Export AzureAD users to CSV file
Introduction
This guide is aimed at exporting the user list from Azure AD to a CSV file.
The guide is describing the use of PowerShell and the methods on how use it and which commands necessary to get the module needed.
Get the Azure AD module
Make sure Azure AD PowerShell module is installed with Install-Module -Name Azure AD
Connect using Connect-AzureAD -confirm
Write AD users to C:\users.csv with Get-AzureADUser | Select-Object GivenName,Surname,UserPrincipalName | ConvertTo-csv -NoTypeInformation | Out-File C:\users.csv
If AzureAD powershell module is not installed, start powershell as Administrator:
Install AzureAD module with the command Install-Module -Name AzureAD:
When Azure AD Module is installed, Connect to the AD using Connect-AzureAD, you can connect in different ways described in the Microsoft article, easiest is just Connect-AzureAD -Confirm (sign in using an account that has access rights to read users, maybe an admin account):
Get users and convert to CSV format
Get AD Users with Get-AzureADUser and select the fields you want, then convert to CSV and put in a file.
For example, to get ADUsers and their GivenName, SurName, Email and convert it to CSV and write it to a file, you could run:
Get-AzureADUser | Select-Object GivenName,Surname,UserPrincipalName | ConvertTo-csv -NoTypeInformation | Out-File C:\users.csv
If you want to add a field like a preset password you can insert it as so (the newline between the label and expression is required): Get-AzureADUser | Select-Object GivenName,Surname,UserPrincipalName, @{Label = "Password"
Expression = {"temporaryPassword"}} | ConvertTo-csv -NoTypeInformation | Out-File C:\users.csv
Microsoft Documentation:
Connect to AzureAD