Can no longer run Powershell script

Silver Contributor

I'm trying to create a script that will copy user accounts from SPO Groups to Office Groups. I'm using an global admin account that has MFA. Yesterday it worked, but today I'm getting the following error: Processing data from remote server outlook.office365.com failed with the following error message: The request for the Windows Remote Shell with ShellId 3AB6B7A1-A423-4D37-B145-1A647B3588C1 failed because the shell was not found on the server. Possible causes are: the specified ShellId is incorrect or the
shell no longer exists on the server. Provide the correct ShellId or create a new shell and retry the operation. 

This is occurring after i get a the login prompt. My script begins with the following code:

$modules = @(Get-ChildItem -Path "$($env:LOCALAPPDATA)\Apps\2.0" -Filter "Microsoft.Exchange.Management.ExoPowershellModule.manifest" -Recurse )
$moduleName = Join-Path $modules[0].Directory.FullName "Microsoft.Exchange.Management.ExoPowershellModule.dll"
Import-Module -FullyQualifiedName $moduleName -Force
$scriptName = Join-Path $modules[0].Directory.FullName "CreateExoPSSession.ps1"
. $scriptName
$null = Connect-EXOPSSession -UserPrincipalName myaccount@tenant.onmicrosoft.com

$exchangeOnlineSession = (Get-PSSession | Where-Object { ($_.ConfigurationName -eq 'Microsoft.Exchange') -and ($_.State -eq 'Opened') })[0]
Import-PSSession $exchangeOnlineSession -AllowClobber -DisableNameChecking
Can anyone tell me what might be causing this problem? 
7 Replies

That's usually a issue on the server-side, simply retrying should route your request to a different server and get it to work. Do you mean that it happens continuously?

 

Why are you loading the module like that btw? You are practically duplicating the connect part.

Thanks, I was having problems connecting that I thought were due to MFA and I  read an article yesterday that showed me this approach https://blogs.technet.microsoft.com/canitpro/2017/08/23/powershell-basics-connecting-to-exchange-onl...

 

Do you have another way that works?

Well that module supports MFA, so you should not have any issues with it. If you want to bypass MFA, best thing to do is configure the "trusted IPs" option, the MFA module will respect that and you can still login with just a password.

 

If you are getting the same error when trying the "regular" way to connect via the MFA module, that's definitely something on the backend, so open a support case.

Hard to know and impossible to debug from a distance.

 

Does the advice given in https://ingogegenwarth.wordpress.com/2018/02/02/exo-ps-mfa/ help?

 

Or of course, Vasil's missive on the topic at https://www.michev.info/Blog/Post/1867/connecting-to-both-exo-and-scc-using-the-mfa-enabled-powershe...

I run into this issue all the time when connecting to Office 365.  I find I have to flush the dns a few times on my system before i get a MS server that works.  Not sure why I have to do that.  It can be very frustrating.

Worked for me. Thank you!
In this case you might have a firewall or proxy that is not set up properly and not including an upto date list of server names and IP addresses