Microsoft 365 : Exchange Online – PowerShell script – Resolving error – New-ExoPSSession : Processing data from remote server outlook.office365.com failed with the following error message: [AuthZRequestId=9ff0b2ed-63de-4871-987a-7a608bc135cc][FailureCategory=AuthZ-AuthorizationException] Fail to create a runspace because you have exceeded the maximum number of connections allowed : 3 for the policy party : MaxConcurrency- Lesson learned
![New-ExoPSSession : Processing data from remote server outlook.office365.com failed with the following error message: [AuthZRequestId=9ff0b2ed-63de-4871-987a-7a608bc135cc][FailureCategory=AuthZ-AuthorizationException] Fail to create a runspace because you have exceeded the maximum number of connections allowed : 3 for the policy](https://i0.wp.com/knowledge-junction.in/wp-content/uploads/2022/06/fig1.png?fit=1554%2C801&ssl=1)
Hi All,
Greetings for the day!!!
Today new issue and solution – lesson learned
Background
- I am writing PowerShell script for searching audit logs using CMDLET – Search-UnifiedAuditLog
- Search-UnifiedAuditLog cmdlet is available in Exchange Online PowerShell
- So first step is to connect Exchange Online PowerShell
- I am connecting to Exchange Online PowerShell using – Connect-ExchangeOnline
- As were testing and executing the script multiple times, on every 4th execution we were getting an error
Issue / Error
New-ExoPSSession : Processing data from remote server outlook.office365.com failed with the following error message: [AuthZRequestId=9ff0b2ed-63de-4871-987a-7a608bc135cc][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_d83f4dfb-c64e-4ff6-808e-84edd3a67d5a,CN=Global Settings,CN=ExchangeLabs,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=INDPRD01,DC=PROD,DC=OUTLOOK,DC=COM;
Snapshot: Owner: Sid~S-1-5-21-4016636904-1928851825-4262717397-23571823~WSMan~false
BudgetType: WSMan
ActiveRunspaces: 3/3
Balance: 600000/1800000/-3000000
PowerShellCmdletsLeft: 200/200
ExchangeCmdletsLeft: 9223372036854775807/Unlimited
CmdletTimePeriod: 5
DestructiveCmdletsLeft: 9223372036854775807/Unlimited
DestructiveCmdletTimePeriod: Unlimited
QueueDepth: Unlimited
MaxRunspacesTimePeriod: 60
RunSpacesRemaining: 5/5
LastTimeFrameUpdate: 5/31/2022 10:23:53 AM
LastTimeFrameUpdateDestructiveCmdlets: 5/31/2022 10:15:57 AM
LastTimeFrameUpdateMaxRunspaces: 5/31/2022 10:23:53 AM
Locked: False
LockRemaining: 00:00:00 For more information, see the about_Remote_Troubleshooting Help topic.
At C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\2.0.5\netFramework\ExchangeOnlineManagement.psm1:475 char:30
- … PSSession = New-ExoPSSession -ExchangeEnvironmentName $ExchangeEnviro …
~~~~~~~~~~~~~- CategoryInfo : ResourceUnavailable: (:) [New-ExoPSSession], PSRemotingTransportException
- FullyQualifiedErrorId : System.Management.Automation.Remoting.PSRemotingDataStructureException,Microsoft.Exchange.Management.ExoPowershellSnapin.NewExoPSSession
![New-ExoPSSession : Processing data from remote server outlook.office365.com failed with the following error message: [AuthZRequestId=9ff0b2ed-63de-4871-987a-7a608bc135cc][FailureCategory=AuthZ-AuthorizationException] Fail to create a runspace because you have exceeded the maximum number of connections allowed : 3 for the policy](https://i0.wp.com/knowledge-junction.in/wp-content/uploads/2022/06/fig1.png?resize=1024%2C528&ssl=1)
Details
- In our PowerShell script we are connecting to the Exchange Online as
Connect-ExchangeOnline
- Connect-ExchangeOnline CMDLET
- This CMDLET allows us to connect to Exchange Online PowerShell using modern authentication
- This cmdlet works for MFA or non-MFA enabled accounts
- This CMDLET creates remote PowerShell connection to our Exchange Online organization
- Cause – Microsoft has a Global Throttling Policy which limits simultaneous connections from one client. Only three simultaneous connections are allowed.
- As we are using Connect-ExchangeOnline CMDLET to connect Exchange Online but we were not disconnecting Exchange Online session at the end of our PowerShell script or on successfully execution of script
- We were not closing the remote connection which we were creating
Solution
- Use the CMDLET – Disconnect-ExchangeOnline as OR
- We could also use the CMDLET – Get-PSSession | Remove-PSSession at the end of PowerShell script
Disconnect-ExchangeOnline -Confirm:$false
Get-PSSession | Remove-PSSession
Thanks for reading!!! Please feel free to discuss in case any questions / suggestions / thoughts !!!
HAVE A GREAT TIME AHEAD !!! LIFE IS BEAUTIFUL 🙂
You must log in to post a comment.