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
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

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\Window
sPowerShell\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
fig : Microsoft 365 – Exchange Online – 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

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 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL. ENJOY THE WHOLE JOURNEY :) Founder of Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.