Just a short PowerShell snippet to list all users with administrative roles in a Microsoft 365 (or Azure AD) environment. In the Admin Portals you can usually only list all the users with a specific role, not all users with any admin role.
You need the Azure AD PowerShell for Graph module installed, and you need to connect to your Azure AD tenant.
- Install the Azure AD PowerShell for Graph module (if you don’t have it yet)
- Connect to your tenant by executing
PowerShell Code to list all admins
Read the following snippet, make sure it’s not malicious or stupid, then execute it. The script outputs a CSV export into
What this doesn’t do
- This snippet doesn’t export which roles the users have
- This snippet doesn’t export App/Service Principals with admin roles
But that’s all that I needed at this moment. Feel free to modify the code to your needs.