The smarter way to manage Microsoft 365. Try AdminDroid for free!
Manage Admin Roles Using Microsoft Graph PowerShell

Manage Admin Roles Using Microsoft Graph PowerShell

Managing admin roles efficiently is a critical responsibility for IT administrators in any Microsoft 365 environment. As organizations scale, administrators frequently need to adjust or remove elevated roles as users transition between projects or responsibilities. While you can assign admin roles in the Microsoft 365 admin center, PowerShell provides greater flexibility and automation to perform bulk operations.

With the deprecation of Azure AD and MS Online modules, it’s time to switch to the modern solution, the Microsoft Graph PowerShell module. In this guide, let’s walk through how you can assign and manage admin role assignments using Microsoft Graph PowerShell.

Pre-Requisites to Manage Admin Roles in Microsoft 365

Before you begin with admin role assignments in Microsoft 365, you ensure to have one of the following roles:

  • Global Administrator
  • Privileged Role Administrator
  • Cloud Application Administrator
  • Microsoft Entra DC Administrator

Manage Administrator Roles Using Microsoft Graph PowerShell

Once you meet the above requirement, you can manage the following tasks using Graph PowerShell:

  1. Get admin roles assigned to a user
  2. Find all users with admin roles
  3. List all users with specific admin role
  4. Assign an admin role to user
  5. Remove admin role from a user
  6. Bulk assign an admin role to users
  7. Bulk assign different admin roles to users
  8. Bulk removal of an admin role from users
  9. Bulk remove multiple admin roles from users

Firstly, connect to the Microsoft Graph PowerShell module with scope “RoleManagement.ReadWrite.Directory” assigned.

1. Get Admin Roles Assigned to a User Using Microsoft Graph PowerShell

To identify which administrator roles are assigned to a specific user, you can use the following Microsoft Graph PowerShell command. Replace <userUPN> with the user’s actual User Principal Name.

This command checks all the directory roles the user belongs to and returns only the admin roles assigned to them.

Get admin roles assigned to a user

2. Find All Users with Admin Roles in Microsoft 365

As part of periodic access reviews, security and compliance teams often need a complete list of all users who hold administrative roles in Microsoft 365. The following script exports each role along with the users assigned to it.

Replace the file path to where you want the CSV to be exported.

The export output file will look like the following:

Find All Users with Admin Roles in Microsoft 365

Tip: You can also use the PowerShell script to get Microsoft 365 admin role reports. It supports modern authentication and is useful for identifying all admins, checking role mappings, and exporting data for audits.

3. List All Users Assigned to a Specific Admin Role in Microsoft 365

You can retrieve all users who are currently assigned to a specific admin role using Microsoft Graph PowerShell. This scenario is particularly valuable for compliance checks, audit reporting, and documenting privileged access across your Microsoft 365 tenant. Simply specify the role name and run the following command set.

Replace <role name> with the actual role you want to query. For example, if you set $roleName=”Global Administrator”, the script will return all users who currently hold the Global Administrator role in your tenant.

List All Users Assigned to a Specific Admin Role in Microsoft 365

4. Assign an Administrator Role to Microsoft 365 User

When delegating permissions in Microsoft 365, always implement the principle of least privilege: assign users only the permissions they need to perform their job. Microsoft provides granular admin roles, such as Exchange Administrator, Teams Administrator, Security Reader, and more. Avoid assigning Global Administrator unnecessarily.

Before assigning a role, it’s a best practice to list all available directory roles in your tenant.

Get the list of all available directory roles

This helps you confirm the exact role name you want to assign.

Once you’ve identified the role from the list, run the script below to assign an admin role to a specific user in Microsoft 365.

Don’t forget to replace the <user UPN> and <role name> you want to assign.

Note: This method is also suitable to assign Microsoft Entra roles in PIM. If you have implemented just-in-time access using PIM, make sure to audit PIM role activations to track temporary admin access elevation and ensure accountability.

5. Remove a User Account from an Administrator Role

Within your access lifecycle management process, certain users will eventually outgrow their elevated roles. The following script helps you remove the appropriate admin role from that user.

Replace <role name> and <user UPN> with the appropriate role and user you want to remove.

6. Bulk Assign a Specific Admin Role to Users in Microsoft 365

Managing administrative roles one by one can be tedious, especially in medium to large organizations. When multiple users need the same elevated access, such as during onboarding, a bulk assignment script can save significant time and reduce errors.

Create a simple CSV containing UserPrincipalName column listing the users who should receive the role.

Bulk Assign a Specific Admin Role to Users in Microsoft 365

The script below automates assigning a specific Microsoft 365 administrator role to a list of users provided in a CSV file.

Replace $RoleName with the administrator role you want to assign, and $CsvPath with the path to your CSV file containing users.

7. Bulk Assign Different Administrator Roles to Users in Microsoft 365

As we know, users require different administrative roles based on their responsibilities. Manually assigning these roles one by one can be slow and error prone. With this CSV-driven bulk assignment approach, you can quickly assign multiple roles to multiple users.

Create a CSV file that lists users and the admin roles need to be assigned. The file should have two columns: UserPrincipalName and RoleName.

Bulk Assign Different Administrator Roles to Users in Microsoft 365

Update $CsvPath to point to the full location of your CSV file that lists users and their roles.

This method ensures that users receive the correct roles quickly and consistently, reducing manual errors and saving administrative time.

8. Bulk Remove Specific Microsoft 365 Admin Role from Users

In Microsoft 365 environments, it’s just as important to remove unnecessary administrative privileges as it is to assign them. Whether for user offboarding, role changes, or periodic audits, cleaning up admin roles in bulk ensures security and reduces the risk of over-privileged accounts.

First, create a CSV file containing the list of users you want to remove the role from. The CSV should have a column named UserPrincipalName with each user’s email.

Bulk Assign a Specific Admin Role to Users in Microsoft 365

Specify $RoleName with the administrator role you want to remove, and $CsvPath with the full path to your CSV file containing users.

This script automates the removal of a specific admin role from multiple users at once, saving time and reducing manual errors.

9. Bulk Remove Different Admin Roles from Different Users

When managing hundreds or thousands of accounts, privilege cleanup can’t be manual. This automated method is ideal during major reorganizations, mergers, or admin role realignments where many users need their elevated access removed simultaneously.

Create a CSV file that includes two columns: UserPrincipalName and RoleName. Each row should specify which role needs to be removed from which user.

Bulk Remove Different Admin Roles from Different Users

Replace $CsvPath with the full path to your CSV file containing the users and roles.

This automated cleanup ensures that users only retain the access they truly need, helping maintain a secure, least-privilege environment.

Best Practices for Assigning Microsoft 365 Roles to Users

Follow these practices to keep your Microsoft 365 environment secure and well-managed:

I hope this blog helps you gain an understanding on how to manage admin roles using Microsoft Graph PowerShell. Feel free to reach us through the comments section if you have any questions.

Manage Admin Roles Using Microsoft Graph PowerShell

by Praba time to read: 7 min
0