Exchange online PowerShell timeout

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:

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