Last active
July 6, 2021 23:00
-
-
Save MatthewJDavis/6b385187cde51b26ac2a03a84d619835 to your computer and use it in GitHub Desktop.
Azure AD priv roles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script to get all User Principal Names of users in the Global Administrators role in Azure Active Directory. | |
# Uses the MSGraph beta endpoint and requires the correct permissions to access the data. See: https://docs.microsoft.com/en-us/graph/api/rbacapplication-list-roledefinitions?view=graph-rest-beta&tabs=http#permissions. | |
Select-MgProfile -Name "beta" | |
Connect-MgGraph -Scopes 'RoleManagement.Read.Directory' | |
$memberList = [System.Collections.Generic.List[string]]::new() | |
$roleId = (Get-MgDirectoryRole -Filter "DisplayName eq 'Global Administrator'").Id | |
$userList = Get-MgDirectoryRoleMember -DirectoryRoleId $roleId | |
foreach ($user in $userList) { | |
$upn = (Get-MgUser -UserId $user.id).UserPrincipalName | |
$memberList.Add($upn) | |
} | |
$memberList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment