forked from directorcia/Office365
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph-globaladmins-get.ps1
32 lines (22 loc) · 984 Bytes
/
graph-globaladmins-get.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<# CIAOPS
Script provided as is. Use at own risk. No guarantees or warranty provided.
Description - Connect to the Microsoft Graph
Source - https://github.com/directorcia/Office365/blob/master/graph-globaladmins-get.ps1
Prerequisites = 1
1. Graph module installed
More scripts available by joining http://www.ciaopspatron.com
#>
import-module Microsoft.Graph.Identity.DirectoryManagement
Connect-MgGraph -Scopes "RoleManagement.Read.Directory","User.Read.All"
$globalAdmins = Get-MgDirectoryRole | Where-Object { $_.displayName -eq "Global Administrator" }
$globalAdminUsers = Get-MgDirectoryRoleMember -DirectoryRoleId $globalAdmins.id
$globaladminsummary = @()
foreach ($adminuser in $globalAdminUsers) {
$user = Get-MgUser -userId $adminuser.Id
$globaladminSummary += [pscustomobject]@{
Id = $adminuser.Id
UserPrincipalName = $user.UserPrincipalName
DisplayName = $user.DisplayName
}
}
$globaladminsummary