Time needed: 2 minutes
Getting a list of all Office 365 Global administrators with Powershell is easy. Here is how to do it with a simple one liner.
- Open a Powershell session and connect to Office 365
At a PowerShell Prompt connect to Office 365 with the command:
Connect-MsolService
- Authenticate with Office 365
Sign in to Office 365 when prompted with a Global Administrator account.
- List Global Admins with the Get-MsolRoleMember cmdlet
Use the following command to list all global admins:
Get-MsolRoleMember -RoleObjectId $(Get-MsolRole -RoleName "Company Administrator").ObjectId
If Connect-MsolService does not work for you, then you need to follow these instructions to install the Azure Active Directory Module.
If you’d like to export the list of Global Administrators to a CSV file instead, use a PowerShell command like the following:
Get-MsolRoleMember -RoleObjectId $(Get-MsolRole -RoleName "Company Administrator").ObjectId | Select-Object -Property DisplayName,EmailAddress | Export-Csv -NoTypeInformation -Path D:\GlobalAdmins.txt
Kathy says
Thanks for sharing. Also, you can try below script to generate multiple Office 365 admin reports based on your requirement. For example,
-All admins report
-Role based admin report
-Get admin roles for a specific user(s)
-Get all admins with a specific role(s).
https://o365reports.com/2021/03/02/Export-Office-365-admin-role-report-powershell/