Hi Vishal Prajapati3
Good day! Thank you for posting to Microsoft Community. We are happy to assist you.
I am truly sorry for the inconvenience this issue has caused you. Based on the description, I understand that you have an issue with export users from the M365 admin center with PowerShell cmdlets
Please understand that this Microsoft answers community is mainly handling or helping users to troubleshoot certain kind of issues of Microsoft 365 for business products, and we are also guiding correct platform to users for some specific concern and requirement. As your inquiry is related to PowerShell cmdlets, we have a separate community team, hence it is recommended to post through PowerShell - Microsoft Q&A, so that a support agent from that team can verify and provide you with the necessary information.
After doing some research and tests, here are a general guideline on how to view Microsoft 365 user accounts with PowerShell. For details, please see: View Microsoft 365 user accounts with PowerShell - Microsoft 365 Enterprise | Microsoft Learn.
- First, install the required software to use Microsoft Graph PowerShell. See Connect to Microsoft 365 with Microsoft Graph PowerShell for more information. The Azure Active Directory (AzureAD) PowerShell module is being deprecated and replaced by the Microsoft Graph PowerShell SDK.
- Then run the following cmdlet to connect to your organization with the required permission scope, which in this case is User.ReadBasic.All:
Connect to Microsoft Graph
- Connect-Graph -Scopes User.Read.All
- To display the full list of user accounts with user ID and user principal name, run this command:
- Get-MgUser -All | Select DisplayName,Id,UserPrincipalName
- Use the following command to export the users report to a CSV file:
- Get-MgUser -All | Select-Object DisplayName, UserPrincipalName, Mail | Export-Csv -Path "C:\Users\YourUsername\Documents\UsersReport.csv" -NoTypeInformation
- This script will export the display name, user principal name, and email of all users to a CSV file located at
C:\Users\YourUsername\Documents\UsersReport.csv. Make sure to replace folder path with where you actually want it.
I hope I have provided you with all the required information to progress the situation. You may also give vote on my reply. With your vote, other users who are facing the same issue can easily find this thread and check suggestion when they search on community. Your vote helps other user to clarify their queries as well.
Feel free to let me know if you have any questions.
Sincerely,
Roger Shen