Comments on: Disabling PowerShell for Exchange Online Users https://practical365.com/exchange-online-powershell-remove/ Practical Office 365 News, Tips, and Tutorials Thu, 12 Oct 2023 08:49:26 +0000 hourly 1 https://wordpress.org/?v=6.3.2 By: Tony Redmond https://practical365.com/exchange-online-powershell-remove/#comment-269117 Tue, 18 Jul 2023 15:54:49 +0000 https://practical365.com/?p=58459#comment-269117 In reply to Doyle.

Very nice. For SDK V2, you’ll need to use Get-MgBetaRoleManagementDirectoryRoleEligibilityScheduleInstance (has anyone said that they hate the SDK cmdlet names?)

Also, you can use Get-MgGroupMember to get the group members if you want to eliminate the Azure AD module as much as possible.

I came up with another solution for PIM assignments in https://office365itpros.com/2023/07/12/privileged-identity-management-ps/. Now I guess I can add eligible assignments to the set.

]]>
By: Doyle https://practical365.com/exchange-online-powershell-remove/#comment-269115 Tue, 18 Jul 2023 15:39:06 +0000 https://practical365.com/?p=58459#comment-269115 In reply to Tony Redmond.

What about this for getting PIM-eligible users and also expanding the PIM-eligible groups using Graph cmdlets?

# Now get the list of users and groups ELIGIBLE for the Exchange and Global Admin roles
$EligibleAssignments = Get-MgRoleManagementDirectoryRoleEligibilityScheduleInstance -ExpandProperty “*” -All
foreach ($Role in $EligibleAssignments) {
If ($Role.RoleDefinition.DisplayName -eq “Exchange Administrator” -or $Role.RoleDefinition.DisplayName -eq “Global Administrator”){
If ($Role.Principal.AdditionalProperties.’@odata.type’ -eq “#microsoft.graph.user”) {
$AdminUsers += $Role.Principal.AdditionalProperties.userPrincipalName
}
elseif ($Role.Principal.AdditionalProperties.’@odata.type’ -eq “#microsoft.graph.group”) {
$AdminUsers += Get-AzureADGroupMember -ObjectId (Get-AzureADGroup -filter “Displayname eq ‘$($Role.Principal.AdditionalProperties.displayName)'”).ObjectId | %{$_.userPrincipalName}
}
}
}

]]>
By: Justin https://practical365.com/exchange-online-powershell-remove/#comment-268035 Tue, 04 Jul 2023 14:11:49 +0000 https://practical365.com/?p=58459#comment-268035 In reply to Tony Redmond.

For the record, it had nothing do with modules but with the session some commands are the same in Exchange Online and on-prem on the Hybrid server.

But I found an good way to avoid it with “Import-PSSession $Session -Prefix Hybrid”

Then Set-User is for Exchange Online and Set-HybridUser is for on-prem.

]]>
By: Tony Redmond https://practical365.com/exchange-online-powershell-remove/#comment-267569 Thu, 29 Jun 2023 10:10:31 +0000 https://practical365.com/?p=58459#comment-267569 In reply to Justin.

There are some cmdlets in the Azure AD module that deal with PIM role assignments. They haven’t been moved to the Microsoft Graph PowerShell SDK yet. When they do, I will update the code to deal with assignments, but your workaround is as good as any for now.

]]>
By: Justin https://practical365.com/exchange-online-powershell-remove/#comment-267567 Thu, 29 Jun 2023 09:58:57 +0000 https://practical365.com/?p=58459#comment-267567 In reply to Tony Redmond.

Yeah I found an way to make it work with an small adjustment regarding the groups, not fool proof since the groups can change:

Adding:
#Get Users from PIM groups
ForEach ($Group in $PIMGroups)
{
[array]$Admins += Get-MgGroupMember -GroupId (Get-MgGroup -Filter “DisplayName eq ‘$Group'”).Id | Select-Object -ExpandProperty AdditionalProperties
}

Adjusting:
[array]$AdminAccounts = $GlobalAdmins.userPrincipalName + $ExoAdmins.userPrincipalName + $Admins.userPrincipalName | Sort-Object -Unique

]]>
By: Tony Redmond https://practical365.com/exchange-online-powershell-remove/#comment-267559 Thu, 29 Jun 2023 08:50:34 +0000 https://practical365.com/?p=58459#comment-267559 In reply to Justin.

Well, that’s a pity… we write PowerShell scripts as examples to explain principles rather than as full-fledged solutions. Feel free to develop your own script!

]]>
By: Justin https://practical365.com/exchange-online-powershell-remove/#comment-267551 Thu, 29 Jun 2023 06:58:57 +0000 https://practical365.com/?p=58459#comment-267551 After further testing I found out that this script has no use for us. It checks only for the Active members in roles and not the eligible ones. (what is the best practice)

]]>
By: Tony Redmond https://practical365.com/exchange-online-powershell-remove/#comment-267406 Tue, 27 Jun 2023 09:22:45 +0000 https://practical365.com/?p=58459#comment-267406 In reply to Justin.

Normally, I use Get-Module to create an array of the loaded modules and then check if the Exchange Online module is loaded:

[array]$Modules = Get-Module | Select-Object -ExpandProperty Name
If (“ExchangeOnlineManagement” -notin $Modules) { Write-Host “Exchange Online not connected” }

]]>
By: Justin https://practical365.com/exchange-online-powershell-remove/#comment-267404 Tue, 27 Jun 2023 08:42:50 +0000 https://practical365.com/?p=58459#comment-267404 In reply to Justin.

Never mind I think I found an way, make sure the on-prem Exchange PS session is not loaded/connected.

I am adjusting this script so it works in an Hybrid environment.

]]>
By: Justin https://practical365.com/exchange-online-powershell-remove/#comment-267402 Tue, 27 Jun 2023 08:32:47 +0000 https://practical365.com/?p=58459#comment-267402 Set-User is an command that is both used on-prem and in the cloud.

How do I make sure it is executed in the cloud and not on-prem?

]]>