Can no longer run Powershell script

%3CLINGO-SUB%20id%3D%22lingo-sub-186374%22%20slang%3D%22en-US%22%3ECan%20no%20longer%20run%20Powershell%20script%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-186374%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20trying%20to%20create%20a%20script%20that%20will%20copy%20user%20accounts%20from%20SPO%20Groups%20to%20Office%20Groups.%20I'm%20using%20an%20global%20admin%20account%20that%20has%20MFA.%20Yesterday%20it%20worked%2C%20but%20today%20I'm%20getting%20the%20following%20error%3A%26nbsp%3BProcessing%20data%20from%20remote%20server%20outlook.office365.com%20failed%20with%20the%20following%20error%20message%3A%20The%20request%20for%20the%20Windows%20Remote%20Shell%20with%20ShellId%203AB6B7A1-A423-4D37-B145-1A647B3588C1%20failed%20because%20the%20shell%20was%20not%20found%20on%20the%20server.%20Possible%20causes%20are%3A%20the%20specified%20ShellId%20is%20incorrect%20or%20the%3CBR%20%2F%3Eshell%20no%20longer%20exists%20on%20the%20server.%20Provide%20the%20correct%20ShellId%20or%20create%20a%20new%20shell%20and%20retry%20the%20operation.%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20is%20occurring%20after%20i%20get%20a%20the%20login%20prompt.%20My%20script%20begins%20with%20the%20following%20code%3A%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3Emodules%3C%2FSPAN%3E%20%3CSPAN%3E%3D%3C%2FSPAN%3E%20%3CSPAN%3E%40(%3C%2FSPAN%3E%3CSPAN%3EGet-ChildItem%3C%2FSPAN%3E%20%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3EPath%20%3C%2FSPAN%3E%3CSPAN%3E%22%3C%2FSPAN%3E%3CSPAN%3E%24(%24%3C%2FSPAN%3E%3CSPAN%3Eenv%3ALOCALAPPDATA%3C%2FSPAN%3E%3CSPAN%3E)%3C%2FSPAN%3E%3CSPAN%3E%5CApps%5C2.0%22%3C%2FSPAN%3E%20%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3EFilter%20%3C%2FSPAN%3E%3CSPAN%3E%22Microsoft.Exchange.Management.ExoPowershellModule.manifest%22%3C%2FSPAN%3E%20%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3ERecurse%20%3C%2FSPAN%3E%3CSPAN%3E)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3EmoduleName%3C%2FSPAN%3E%20%3CSPAN%3E%3D%3C%2FSPAN%3E%20%3CSPAN%3EJoin-Path%3C%2FSPAN%3E%20%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3Emodules%3C%2FSPAN%3E%3CSPAN%3E%5B%3C%2FSPAN%3E%3CSPAN%3E0%3C%2FSPAN%3E%3CSPAN%3E%5D%3C%2FSPAN%3E%3CSPAN%3E.Directory.FullName%20%3C%2FSPAN%3E%3CSPAN%3E%22Microsoft.Exchange.Management.ExoPowershellModule.dll%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EImport-Module%3C%2FSPAN%3E%20%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3EFullyQualifiedName%20%3C%2FSPAN%3E%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3EmoduleName%3C%2FSPAN%3E%20%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3EForce%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3EscriptName%3C%2FSPAN%3E%20%3CSPAN%3E%3D%3C%2FSPAN%3E%20%3CSPAN%3EJoin-Path%3C%2FSPAN%3E%20%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3Emodules%3C%2FSPAN%3E%3CSPAN%3E%5B%3C%2FSPAN%3E%3CSPAN%3E0%3C%2FSPAN%3E%3CSPAN%3E%5D%3C%2FSPAN%3E%3CSPAN%3E.Directory.FullName%20%3C%2FSPAN%3E%3CSPAN%3E%22CreateExoPSSession.ps1%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E.%3C%2FSPAN%3E%20%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3EscriptName%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24null%3C%2FSPAN%3E%20%3CSPAN%3E%3D%3C%2FSPAN%3E%20%3CSPAN%3EConnect-EXOPSSession%3C%2FSPAN%3E%20%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3EUserPrincipalName%20myaccount%40tenant%3C%2FSPAN%3E%3CSPAN%3E.onmicrosoft.com%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3EexchangeOnlineSession%3C%2FSPAN%3E%20%3CSPAN%3E%3D%3C%2FSPAN%3E%20%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3EGet-PSSession%3C%2FSPAN%3E%20%3CSPAN%3E%7C%3C%2FSPAN%3E%20%3CSPAN%3EWhere-Object%3C%2FSPAN%3E%3CSPAN%3E%20%7B%20%3C%2FSPAN%3E%3CSPAN%3E(%24%3C%2FSPAN%3E%3CSPAN%3E_%3C%2FSPAN%3E%3CSPAN%3E.ConfigurationName%3C%2FSPAN%3E%20%3CSPAN%3E-eq%3C%2FSPAN%3E%20%3CSPAN%3E'Microsoft.Exchange'%3C%2FSPAN%3E%3CSPAN%3E)%3C%2FSPAN%3E%20%3CSPAN%3E-and%3C%2FSPAN%3E%20%3CSPAN%3E(%24%3C%2FSPAN%3E%3CSPAN%3E_%3C%2FSPAN%3E%3CSPAN%3E.State%3C%2FSPAN%3E%20%3CSPAN%3E-eq%3C%2FSPAN%3E%20%3CSPAN%3E'Opened'%3C%2FSPAN%3E%3CSPAN%3E)%3C%2FSPAN%3E%3CSPAN%3E%20%7D%3C%2FSPAN%3E%3CSPAN%3E)%3C%2FSPAN%3E%3CSPAN%3E%5B%3C%2FSPAN%3E%3CSPAN%3E0%3C%2FSPAN%3E%3CSPAN%3E%5D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EImport-PSSession%3C%2FSPAN%3E%20%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3EexchangeOnlineSession%3C%2FSPAN%3E%20%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3EAllowClobber%20%3C%2FSPAN%3E%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3EDisableNameChecking%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3ECan%20anyone%20tell%20me%20what%20might%20be%20causing%20this%20problem%3F%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%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%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F64%22%20target%3D%22_blank%22%3E%40Tony%20Redmond%3C%2FA%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-186374%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExchange%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-314033%22%20slang%3D%22en-US%22%3ERe%3A%20Can%20no%20longer%20run%20Powershell%20script%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-314033%22%20slang%3D%22en-US%22%3EIn%20this%20case%20you%20might%20have%20a%20firewall%20or%20proxy%20that%20is%20not%20set%20up%20properly%20and%20not%20including%20an%20upto%20date%20list%20of%20server%20names%20and%20IP%20addresses%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-313820%22%20slang%3D%22en-US%22%3ERe%3A%20Can%20no%20longer%20run%20Powershell%20script%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-313820%22%20slang%3D%22en-US%22%3EWorked%20for%20me.%20Thank%20you!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-285908%22%20slang%3D%22en-US%22%3ERe%3A%20Can%20no%20longer%20run%20Powershell%20script%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-285908%22%20slang%3D%22en-US%22%3E%3CP%3EI%20run%20into%20this%20issue%20all%20the%20time%20when%20connecting%20to%20Office%20365.%26nbsp%3B%20I%20find%20I%20have%20to%20flush%20the%20dns%20a%20few%20times%20on%20my%20system%20before%20i%20get%20a%20MS%20server%20that%20works.%26nbsp%3B%20Not%20sure%20why%20I%20have%20to%20do%20that.%26nbsp%3B%20It%20can%20be%20very%20frustrating.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-186564%22%20slang%3D%22en-US%22%3ERe%3A%20Can%20no%20longer%20run%20Powershell%20script%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-186564%22%20slang%3D%22en-US%22%3E%3CP%3EHard%20to%20know%20and%20impossible%20to%20debug%20from%20a%20distance.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDoes%20the%20advice%20given%20in%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fingogegenwarth.wordpress.com%2F2018%2F02%2F02%2Fexo-ps-mfa%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fingogegenwarth.wordpress.com%2F2018%2F02%2F02%2Fexo-ps-mfa%2F%3C%2FA%3E%20help%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOr%20of%20course%2C%20Vasil's%20missive%20on%20the%20topic%20at%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fwww.michev.info%2FBlog%2FPost%2F1867%2Fconnecting-to-both-exo-and-scc-using-the-mfa-enabled-powershell-module%26nbsp%3B%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.michev.info%2FBlog%2FPost%2F1867%2Fconnecting-to-both-exo-and-scc-using-the-mfa-enabled-powershell-module%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-186499%22%20slang%3D%22en-US%22%3ERe%3A%20Can%20no%20longer%20run%20Powershell%20script%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-186499%22%20slang%3D%22en-US%22%3E%3CP%3EWell%20that%20module%20supports%20MFA%2C%20so%20you%20should%20not%20have%20any%20issues%20with%20it.%20If%20you%20want%20to%20bypass%20MFA%2C%20best%20thing%20to%20do%20is%20configure%20the%20%22trusted%20IPs%22%20option%2C%20the%20MFA%20module%20will%20respect%20that%20and%20you%20can%20still%20login%20with%20just%20a%20password.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20are%20getting%20the%20same%20error%20when%20trying%20the%20%22regular%22%20way%20to%20connect%20via%20the%20MFA%20module%2C%20that's%20definitely%20something%20on%20the%20backend%2C%20so%20open%20a%20support%20case.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-186491%22%20slang%3D%22en-US%22%3ERe%3A%20Can%20no%20longer%20run%20Powershell%20script%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-186491%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%2C%20I%20was%20having%20problems%20connecting%20that%20I%20thought%20were%20due%20to%20MFA%20and%20I%26nbsp%3B%20read%20an%20article%20yesterday%20that%20showed%20me%20this%20approach%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fblogs.technet.microsoft.com%2Fcanitpro%2F2017%2F08%2F23%2Fpowershell-basics-connecting-to-exchange-online-using-multi-factor-authentication%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fblogs.technet.microsoft.com%2Fcanitpro%2F2017%2F08%2F23%2Fpowershell-basics-connecting-to-exchange-online-using-multi-factor-authentication%2F%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EDo%20you%20have%20another%20way%20that%20works%3F%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-186479%22%20slang%3D%22en-US%22%3ERe%3A%20Can%20no%20longer%20run%20Powershell%20script%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-186479%22%20slang%3D%22en-US%22%3E%3CP%3EThat's%20usually%20a%20issue%20on%20the%20server-side%2C%20simply%20retrying%20should%20route%20your%20request%20to%20a%20different%20server%20and%20get%20it%20to%20work.%20Do%20you%20mean%20that%20it%20happens%20continuously%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhy%20are%20you%20loading%20the%20module%20like%20that%20btw%3F%20You%20are%20practically%20duplicating%20the%20connect%20part.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Respected 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
Highlighted

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.

Highlighted

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?

Highlighted

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.

Highlighted

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

Highlighted

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.

Highlighted
Worked for me. Thank you!
Highlighted
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