Are you on a third-party PowerShell site? This is mistake;)
If you interact with Async callbacks, the problem is that you are working in a different thread, and the [Runspace]::DefaultRunspacethread is static. @ x0n wrote a bridge for Async Callbacks a while ago (I'll see if I can find it).
On the bottom line, you should do what the error suggests: provide one of the DefaultRunspace properties of type System.Management.Automation.Runspaces.Runspace. But you have to do it from the thread where the code will be executed, so it is a little rude with asynchronous callbacks.
[Management.Automation.Runspaces.Runspace]::DefaultRunspace = [RunspaceFactory]::CreateRunspace()
source
share