Exchange online PowerShell timeout

%3CLINGO-SUB%20id%3D%22lingo-sub-1985615%22%20slang%3D%22en-US%22%3EExchange%20online%20PowerShell%20timeout%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1985615%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20All%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20running%20one%20PowerShell%20script%20is%20a%20long-running%20script.%20Initially%2C%20it%20is%20running%20successfully%20after%2090%20min%20approx%20it%20starts%20giving%20an%20error%20that%20cmdlet%20not%20recognized.%20For%20example%20below%20error%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23FF6600%22%3Eget-mailboxstatistics%20%3A%20The%20term%20'get-mailboxstatistics'%20is%20not%20recognized%20as%20the%20name%20of%20a%20cmdlet%2C%20function%2C%20script%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%23FF6600%22%3Efile%2C%20or%20operable%20program.%20Check%20the%20spelling%20of%20the%20name%2C%20or%20if%20a%20path%20was%20included%2C%20verify%20that%20the%20path%20is%20correct%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%23FF6600%22%3Eand%20try%20again.%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23FF6600%22%3EAt%20C%3A%5CUsers%5CAdmin%5CDesktop%5Carchive.ps1%3A17%20char%3A17%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%23FF6600%22%3E%2B%20%24archivestats%20%3D%20get-mailboxstatistics%20%24mailbox.userprincipalname%20-arc%20...%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%23FF6600%22%3E%2B%20~~~~~~~~~~~~~~~~~~~~~%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%23FF6600%22%3E%2B%20CategoryInfo%20%3A%20ObjectNotFound%3A%20(get-mailboxstatistics%3AString)%20%5B%5D%2C%20CommandNotFoundException%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%23FF6600%22%3E%2B%20FullyQualifiedErrorId%20%3A%20CommandNotFoundException%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1985615%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExchange%20Online%20PowerShell%20V2%20module%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1986035%22%20slang%3D%22en-US%22%3ERe%3A%20Exchange%20online%20PowerShell%20timeout%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1986035%22%20slang%3D%22en-US%22%3E%3CP%3EThat's%20a%20standard%20issue%20with%20session%20disconnect.%20Plenty%20of%20articles%2Fthreads%20on%20how%20to%20optimize%20code%20to%20account%20for%20this%20are%20available%20online%2C%20for%20example%20this%20blog%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fexchange-team-blog%2Frunning-powershell-cmdlets-for-large-numbers-of-users-in-office%2Fba-p%2F604280%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fexchange-team-blog%2Frunning-powershell-cmdlets-for-large-numbers-of-users-in-office%2Fba-p%2F604280%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2146155%22%20slang%3D%22en-US%22%3ERe%3A%20Exchange%20online%20PowerShell%20timeout%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2146155%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F58%22%20target%3D%22_blank%22%3E%40Vasil%20Michev%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20is%20it%20that%20before%20I%20was%20able%20to%20run%20such%20scripts%20against%20Office%20365%20and%20now%20I%20can't%20anymore%3F%3C%2FP%3E%3CP%3EI%20can't%20seem%20to%20be%20able%20to%20accommodate%20the%20script%20wrapper%20into%20my%20script.%26nbsp%3B%3C%2FP%3E%3CP%3ENot%20to%20mention%20the%20fact%20that%20the%20session%20doesn't%20actually%20become%20broken%2C%20somehow%20it%20remains%20opened%20but%20no%20EXO%20cmdlets%20available%20anymore.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hi All,

 

I am running one PowerShell script is a long-running script. Initially, it is running successfully after 90 min approx it starts giving an error that cmdlet not recognized. For example below error

 

get-mailboxstatistics : The term 'get-mailboxstatistics' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.

At C:\Users\Admin\Desktop\archive.ps1:17 char:17
+ $archivestats = get-mailboxstatistics $mailbox.userprincipalname -arc ...
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (get-mailboxstatistics:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

2 Replies

That's a standard issue with session disconnect. Plenty of articles/threads on how to optimize code to account for this are available online, for example this blog: https://techcommunity.microsoft.com/t5/exchange-team-blog/running-powershell-cmdlets-for-large-numbe...

@Vasil Michev 

How is it that before I was able to run such scripts against Office 365 and now I can't anymore?

I can't seem to be able to accommodate the script wrapper into my script. 

Not to mention the fact that the session doesn't actually become broken, somehow it remains opened but no EXO cmdlets available anymore.