Microsoft 365 : Microsoft Graph PowerShell tutorial – Part 4 – Implementing Governance – Fetching all Global Administrators in tenant

Microsoft PowerShell Graph - Executing CMDLET "Get-MgDirecotoryRoleMember" - fetching all Global Administrators
Microsoft PowerShell Graph - Executing CMDLET "Get-MgDirecotoryRoleMember" - fetching all Global Administrators

Hi All,

Greetings for the day!

Continuing our learning on Microsoft Graph PowerShell.

Today one more PowerShell in our PowerShell bucket. This is 4th article in series. Discussing one of the feature of Microsoft 365 Governance. Fetching list of Global Administrators. Getting to know how many number of Global Administrators in our tenant.

We have a good series going on Microsoft Graph PowerShell OR If you are beginner to Microsoft Graph PowerShell. Kindly please have a look

Steps

  • Connect to Microsoft Graph using Connect-MgGraph with delegated permissions to read roles.
  • As we need read only permissions to roles – We need get “Global Administrator” role – RoleManagement.Read.Directory
#connect to Microsoft Graph - with delegated permissions - RoleManagement.Read.Directory 
Connect-MgGraph -Scopes RoleManagement.Read.Directory

  • As we execute above CMDLET, we will have “Sign in to your account” dialog as shown in below figure

Executing Connect-MgGraph with permissions -"RoleManagement.Read.Directory" - "Permission Requests" dialog
fig: Executing Connect-MgGraph with delegated permissions -“RoleManagement.Read.Directory” – “Permission Requests” dialog
Executing Connect-MgGraph with permissions -"RoleManagement.Read.Directory" - "Permission Requests" dialog
Fig : Executing Connect-MgGraph with delegated permissions -“RoleManagement.Read.Directory” – “Permission Requests” dialog
  • Please check the “Consent on behalf of your organization” and click on “Accept” button
  • On successful execution, we will be connected to Microsoft Graph
  • Lets execute – Get-MgDirectoryRole CMDLET to get all roles available in tenant
Get-MgDirectoryRole | Select DisplayName, Description

Microsoft PowerShell Graph - Executing CMDLET "Get-MgDirecotoryRole" - fetching all roles in tenant
fig : Microsoft PowerShell Graph – Executing CMDLET “Get-MgDirecotoryRole” – fetching all roles in tenant
  • We will get specific role like – “Global Administrator” using filter on DisplayName as in below code snippet
  • We will store role in role object. We will use ID property to get the all role members
#Fetch "Global Administrator" role
$Role = Get-MgDirectoryRole | Where {$_.DisplayName -eq "Global Administrator"}

output:

DeletedDateTime Id                                   Description                                                                            
--------------- --                                   -----------                                                                            
                b22d52e1-b7e1-4c17-a542-0fa7df7f89fb Can manage all aspects of Microsoft Entra ID and Microsoft services that use Microso...

Microsoft PowerShell Graph - Executing CMDLET "Get-MgDirecotoryRole" - fetching "Global Administrator" role
fig : Microsoft PowerShell Graph – Executing CMDLET “Get-MgDirecotoryRole” – fetching “Global Administrator” role

  • Next, with the help of Role object and Id property we will get all the members of given role – “Global Administrator” using – Get-MgDirectoryRoleMember CMDLET

#Fetch all members of the "Global Administrator" role
$AllGA = Get-MgDirectoryRoleMember -DirectoryRoleId $Role.Id
$AllGA | Select Id,AdditionalProperties | Format-List

Microsoft PowerShell Graph - Executing CMDLET "Get-MgDirecotoryRoleMember" - fetching all Global Administrators
fig : Microsoft PowerShell Graph – Executing CMDLET “Get-MgDirecotoryRoleMember” – fetching all Global Administrators

  • From above snap – we have two Global Administrators in our tenant

In this way, we will get members of any role (SharePoint administrators, Teams administrators) and track.

Thanks for reading ! Stay tuned for more articles on Microsoft Graph PowerShell and PowerShell !

HAPPY LEARNING AHEAD 🙂 LIFE IS BEAUTIFUL 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL. ENJOY THE WHOLE JOURNEY :) Founder of Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

1 Response

  1. December 3, 2024

    […] To know all the “Global Administrators” in my tenant, using Microsoft Graph PowerShell, please refer article. Microsoft 365 : Microsoft Graph PowerShell tutorial – Part 4 – Implementing Governance – Fetching all Global Administrators in tenant – https://microsoft365junction.com/2024/01/23/microsoft-365-microsoft-graph-powershell-tutorial-part-4… […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Microsoft 365

Subscribe now to keep reading and get access to the full archive.

Continue reading