Forum Discussion
Statement separator within scriptblock
Invoke-Command -Session $SessionVariable -ScriptBlock {Get-RemoteMailbox -Identity UserName ; Get-User -Identity UserName}
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.
2 Replies
- MichaelHogendoorn_CPCopper ContributorWe have the same behavior JRE77. Did you find a solution yet?
- JRE77Copper Contributor
Take a look at "Known Issues" section in https://techcommunity.microsoft.com/t5/exchange-team-blog/released-april-2021-exchange-server-security-updates/ba-p/2254617.
"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()