gpt4 book ai didi

azure - 如何关闭 Office365 Exchange Powershell 连接

转载 作者:行者123 更新时间:2023-12-03 04:11:36 24 4
gpt4 key购买 nike

当我连接到 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

最佳答案

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

# your code
# ...

if ($ExoSession) { Remove-PSSession -Session $ExoSession -ErrorAction SilentlyContinue } }

或者,通过在创建新 session 之前添加此行,首先删除所有可能的现有 session :

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

希望有帮助

关于azure - 如何关闭 Office365 Exchange Powershell 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56251464/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com