默认情况下,允许在 Microsoft 365 中创建的所有帐户都可以使用 Exchange Online PowerShell。管理员可以使用 Exchange Online PowerShell 启用或禁用用户连接到 Exchange Online PowerShell 的能力。
1.在Windows10或Windows11系统上,以管理员身份打开Powershell并运行如下命令:
$UserCredential = Get-Credential
# 在显示的 Windows PowerShell 凭据请求对话框中,键入您的帐户和密码,然后单击"确定"
Connect-ExchangeOnline [-Credential $UserCredential] -ShowProgress $true [-ExchangeEnvironmentName <Value>]
#使用上面的$UserCredential变量,选择Exchange Online环境名称,例如:O365China
具体示例:
$UserCredential = Get-Credential
Connect-ExchangeOnline -Credential $UserCredential -ShowProgress $true -ExchangeEnvironmentName O365China
2.对单个用户禁用或启用Exchange Online PowerShell的访问,具体命令及操作如下:
Set-User -Identity TL01@mk10.online -RemotePowerShellEnabled $false
Set-User -Identity TL01@mk10.online -RemotePowerShellEnabled $true
多个用户批量禁用或启用Exchange Online PowerShell访问功能,具体命令及操作如下:
$Users = Get-User -ResultSize unlimited -Filter "RecipientType -eq 'UserMailbox'"
$Users | foreach {Set-User -Identity $_ -RemotePowerShellEnabled $false}
$Users = Get-User -ResultSize unlimited -Filter "RecipientType -eq 'UserMailbox'"
$Users | foreach {Set-User -Identity $_ -RemotePowerShellEnabled $true}