Azure 如何关闭Office365 Exchange Powershell连接

Azure 如何关闭Office365 Exchange Powershell连接,azure,powershell,automation,exchange-server,ps,Azure,Powershell,Automation,Exchange Server,Ps,当我连接到Office365 Exchange时,会出现一条错误消息。如何关闭此连接 脚本: $userCredential = Get-AutomationPSCredential -Name 'automation' $ExoSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Creden

当我连接到Office365 Exchange时,会出现一条错误消息。如何关闭此连接

脚本:

$userCredential = Get-AutomationPSCredential -Name 'automation'


$ExoSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $userCredential -Authentication Basic -AllowRedirection
Import-PSSession $ExoSession

Get-Mailbox -ResultSize Unlimited -Filter {RecipientTypeDetails -eq "UserMailbox" -or RecipientTypeDetails -eq "SharedMailbox" -or RecipientTypeDetails -eq "RoomMailbox" -or RecipientTypeDetails -eq "DiscoveryMailbox"} | Set-Mailbox -AuditEnabled $true -AuditLogAgeLimit 180 -AuditAdmin Update, MoveToDeletedItems, SoftDelete, HardDelete, SendAs, SendOnBehalf, Create, UpdateFolderPermission -AuditDelegate Update, SoftDelete, HardDelete, SendAs, Create, UpdateFolderPermissions, MoveToDeletedItems, SendOnBehalf -AuditOwner UpdateFolderPermission, MailboxLogin, Create, SoftDelete, HardDelete, Update, MoveToDeletedItems
错误:

New-PSSession : [outlook.office365.com] Processing data from remote server outlook.office365.com failed with the 
 following error message: 
 [AuthZRequestId=fe5eb99c-df73-4899-b445-ad91e0ecf1f3][FailureCategory=AuthZ-AuthorizationException] Fail to create a 
 runspace because you have exceeded the maximum number of connections allowed : 3 for the policy party : MaxConcurrency. 
 Please close existing runspace and try again.
 Policy: CN=GlobalThrottlingPolicy_cfaee113-6e8e-4889-aa2c-99baf345f85f,CN=Global Settings,CN=ExchangeLabs,CN=Microsoft 
 Exchange,CN=Services,CN=Configuration,DC=eurprd04,DC=prod,DC=outlook,DC=com; 
 LockRemaining: 00:00:00 For more information, see the about_Remote_Troubleshooting Help topic.
 At line:4 char:15
 + ... xoSession = New-PSSession -ConfigurationName Microsoft.Exchange -Conn ...
 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 + CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], 
 PSRemotingTransportException
 + FullyQualifiedErrorId : IncorrectProtocolVersion,PSSessionOpenFailed

您可以在完成代码后立即关闭/删除会话:

# your code
# ...

if ($ExoSession) { Remove-PSSession -Session $ExoSession -ErrorAction SilentlyContinue } }
或者,在创建新会话之前添加此行,首先删除所有可能的现有会话:

Get-PSSession | Where-Object { $_.ConfigurationName -eq 'Microsoft.Exchange' } | Remove-PSSession -ErrorAction SilentlyContinue

希望有帮助

您可以在完成代码后立即关闭/删除会话:

# your code
# ...

if ($ExoSession) { Remove-PSSession -Session $ExoSession -ErrorAction SilentlyContinue } }
或者,在创建新会话之前添加此行,首先删除所有可能的现有会话:

Get-PSSession | Where-Object { $_.ConfigurationName -eq 'Microsoft.Exchange' } | Remove-PSSession -ErrorAction SilentlyContinue

希望对您有所帮助

您想测试连接是否失败吗?我们没有收到您的来信。。我的回答解决了你的问题吗?如果是,请点击✓ 在左边。这将帮助其他有类似问题的人更容易地找到它。您是否要测试连接是否失败?我们没有收到您的消息。。我的回答解决了你的问题吗?如果是,请点击✓ 在左边。这将帮助其他有类似问题的人更容易地找到它。