I worked quite a bit with PowerShell runspaces and I know it's possible to invoke commands in another runspace by using a dispatcher from WPF-objects.
I create my runspaces like this:
$global:A = [hashtable]::Synchronized(@{})
$global:initialSessionState = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault()
# Add some functions to the ISS
$GuiRunspace =[runspacefactory]::CreateRunspace($initialSessionState)
$GuiRunspace.ApartmentState = "STA"
$GuiRunspace.Open()
$GuiRunspace.SessionStateProxy.SetVariable("A",$A)
$GuiRunspace.SessionStateProxy.SetVariable("B",$B)
$GuiRunspace.Name = "GuiRunspace"
$Gui = [powershell]::Create()
[void]$Gui.addscript($GUILayerScript)
$Gui.Runspace = $GuiRunspace
$GuiThread = $Gui.beginInvoke()
And with the following code, I can manipulate that runspace from other runspaces:
$A.Window.Dispatcher.invoke({ *Do some crazy stuff that has nothing to do with the object from which you called the dispatcher* })
This only works because the window is a WPF-object that has the dispatcher property.
The question is, how do I invoke a command in other runspaces without a WPF-dispatcher?