-
Notifications
You must be signed in to change notification settings - Fork 15
/
Investigate_Admin_Roles.ps1
46 lines (32 loc) · 1.64 KB
/
Investigate_Admin_Roles.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Set-Location c:\
Clear-Host
#We need the PowerShell module
Install-Module MSOnline -AllowClobber -Force -Verbose
#Connect to Microsoft 365 (formerly Office365)
Connect-MsolService
#Did it work
Get-MsolUser
#We search the properties of Get-MsolUser
Get-MsolUser | Get-Member
#Just so, who has a license
Get-MsolUser -All | where {$_.IsLicensed -ne $null} | Select-Object -Property Displayname, UserPrincipalName
#Just so, who has no license
Get-MsolUser -All | where {$_.IsLicensed -eq $false} | Select-Object -Property Displayname, UserPrincipalName
#The last password change time stamp
Get-MsolUser -All | Select DisplayName,UserPrincipalName,LastPasswordChangeTimeStamp
#Listing the admin roles
Get-MsolRole | Out-GridView
#Note: The names of the roles differ from the Azure AD
#Who is Global Admin?
$comrole = Get-MsolRole -RoleName "Company Administrator"
Get-MsolRoleMember -RoleObjectId $comrole.ObjectId
#Who is Exchange Online Admin?
$exorole = Get-MsolRole -RoleName "Exchange Service Administrator"
Get-MsolRoleMember -RoleObjectId $exorole.ObjectId
#And where is SharePoint Online Admin?
$sporole = Get-MsolRole -RoleName "SharePoint Service Administrator"
Get-MsolRoleMember -RoleObjectId $sporole.ObjectId
#How about a cool solution?
Get-MsolRole | %{$role = $_.name; Get-MsolRoleMember -RoleObjectId $_.objectid} | select @{Name="Role"; Expression = {$role}}, DisplayName, EmailAddress
#Please somewhat sorted!
Get-MsolRole | %{$role = $_.name; Get-MsolRoleMember -RoleObjectId $_.objectid} | select @{Name="Role"; Expression = {$role}}, DisplayName, EmailAddress | Sort-Object -Property Displayname