Skip to content

Commit 461deb2

Browse files
authored
Refactor AdminUsers retrieval in PowerShell script
1 parent 4a9af69 commit 461deb2

1 file changed

Lines changed: 1 addition & 7 deletions

File tree

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardDisableExchangeOnlinePowerShell.ps1

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,7 @@ function Invoke-CIPPStandardDisableExchangeOnlinePowerShell {
4343

4444
try {
4545

46-
$RoleAssignments = New-GraphGetRequest -uri 'https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments?$expand=principal' -tenantid $Tenant
47-
$DirectAdminUPNs = ($RoleAssignments | Where-Object { $_.principal.'@odata.type' -eq '#microsoft.graph.user' }).principal.userPrincipalName
48-
$AdminGroupIds = ($RoleAssignments | Where-Object { $_.principal.'@odata.type' -eq '#microsoft.graph.group' }).principal.id | Select-Object -Unique
49-
$GroupMemberUPNs = foreach ($GroupId in $AdminGroupIds) {
50-
(New-GraphGetRequest -uri "https://graph.microsoft.com/v1.0/groups/$GroupId/transitiveMembers/microsoft.graph.user?`$select=userPrincipalName" -tenantid $Tenant).userPrincipalName
51-
}
52-
$AdminUsers = @($DirectAdminUPNs) + @($GroupMemberUPNs) | Where-Object { $_ } | Select-Object -Unique
46+
$AdminUsers = (New-GraphGetRequest -uri 'https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments?$expand=principal' -tenantid $Tenant).principal.userPrincipalName
5347
$UsersWithPowerShell = New-ExoRequest -tenantid $Tenant -cmdlet 'Get-User' -Select 'userPrincipalName, identity, guid, remotePowerShellEnabled' | Where-Object { $_.RemotePowerShellEnabled -eq $true -and $_.userPrincipalName -notin $AdminUsers }
5448
$PowerShellEnabledCount = ($UsersWithPowerShell | Measure-Object).Count
5549
$StateIsCorrect = $PowerShellEnabledCount -eq 0

0 commit comments

Comments
 (0)