Statement separator within scriptblock

Copper Contributor
Running Exchange 2013 CU23.
I created a session to Exchange 2013 and saved it as a variable. After running the following command...:

 

Invoke-Command -Session $SessionVariable -ScriptBlock {Get-RemoteMailbox -Identity UserName ; Get-User -Identity UserName}

 

...I get the following error:

 

The syntax is not supported by this runspace. This can occur if the runspace is in no-language mode.

 

If I split-up the single command into two separate statements...:

 

Invoke-Command -Session $SessionVariable -ScriptBlock {Get-RemoteMailbox -Identity UserName}
Invoke-Command -Session $SessionVariable -ScriptBlock {Get-User -Identity UserName}

 

...it completes successfully.

Anybody else having this issue? This only happened within that past few days and I can't think of what's causing the issue.
2 Replies
We have the same behavior JRE77. Did you find a solution yet?

@MichaelHogendoorn_CP 

Take a look at "Known Issues" section in https://techcommunity.microsoft.com/t5/exchange-team-blog/released-april-2021-exchange-server-securi....

 

"After application of the Exchange Server April security update CMDlets executed against the Exchange Management Console using an invoked runspace might fail with the following error message:
The syntax is not supported by this runspace. This can occur if the runspace is in no-language mode.
This behavior is expected; please change any code using .AddScript() to use .AddCommand() for continued compatibility."

 

I'm just an amateur Powershell scripter, so I have no idea how to use .AddScript() and .AddCommand()