Glad I found this page: Same root issue - bizarrely ExchangeOnlineManagement can't differentiate existing onprem ExchangeMgmtShell remoting PSSession from EOM's own remoting session.
Mine is in the lack of a populated session prefix - because ExchOnPrem doesn't have one (my EOM session does)...
text
*Creating a new Remote PowerShell session using Modern Authentication for implicit remoting of "Get-Mailbox" command ...
Exception calling "GetSteppablePipeline" with "1" argument(s): "Cannot validate argument on parameter 'Prefix'. The argument is null. Provide a valid value for the
argument, and then try running the command again."
At C:\Users\XXX\AppData\Local\Temp\2\tmp_y3tpoqfw.aup\tmp_y3tpoqfw.aup.psm1:19688*
- post the above the test-ActiveToken (for EOM) says token is valid
- and not surprisingly only the 9 bannered get-exo[Noun] cmdlets work.
- the "legacy" cmdlets, which require implicit remoting, die hard.
Debugs to the import-pssession call in ..\Modules\ExchangeOnlineManagement\2.0.5\netFramework\ExchangeOnlineManagement.psm1, line #159: in global:UpdateImplicitRemotingHandler():
powershell
$CurrentModule = Import-Module $PSSessionModuleInfo.Path -Global -DisableNameChecking -Prefix $script:MyModule.ModulePrefix -PassThru ;
- qry the value:
$script:MyModule | fl pre*
Prefix :
- and Prefix is blank
It looks like the module's choice of $script:PSSession, is mismatching, the EXOnPrem's PsSession.
I'd been doing a full disconnect & reconnect, to try to work around.
But with the tips above, I'm now going to precheck status - not sure how yet - and run a
disconnect-exoOnPrem; Disconnect-ExchangeOnline ; connect-ExchangeOnline ; connect-exOnPrem;
... as a sort of "lame" workaround.
Though, as this doesn't reflect an expired token, and is randomly generated by running legacy implicit remoted cmdlets, I'm not sure how to trap and smootly work around this baloney, other than running a disconnect/reconnect cycle prior to running any given EOM legacy cmdlet.
I may just hack the .psm1 above and coerce things back to function, as I can see it's been quite awhile with the issue open, no solution other than closing & re-instantiating all implicit remoting, and it's a pretty lame workaround to refresh all connections around all but nine common cmdlets for EXO. What a mess.
N.b. it's also somewhat disturbing that MS support straight-faced asks "why?" one would run ExchangeOnlineManagement& onprem EMS modules in the same session?
Really? That's an extremely parochial view. Most enterprises with onprem AD as object Source of Authority are going to run hybrid systems and objects. Heck, I just fixed a 'no brain' (missing mbx both ends, due to delicense & re-hire), that pretty solidly requires editing both the AD source of authority ADUser, and the hybrid ExOnPrem Remotemailbox object (remapping guid to EXO mbx guid, and setting RemoteRoutingAddress to match), at the same time you query & update the EXO mailbox & AzureADuser object...
It's frequently clear that this material isn't really designed for enterprise use... It's 100% lowest common denominator.