Hey all,
Im trying to figure out how to setup a scriptblock that defines a bunch of mixed data (functions, variables) and then import & execute it into newly created runspaces. $sharedData gets imported, but it doesnt look like its executing and defining $myvariable inside the new runspace.
example:
$syncHash = [hashtable]::Synchronized(@{})
$sharedData = {$Myvariable = “wootwoot”}
$RunSpaceNew =[runspacefactory]::CreateRunspace()
$RunSpaceNew.ApartmentState = “STA”
$RunSpaceNew.ThreadOptions = “UseNewThread”
$RunSpaceNew.Open()
$RunSpaceNew.SessionStateProxy.SetVariable(“syncHash”,$syncHash)
$RunSpaceNew.SessionStateProxy.SetVariable(“sharedData”,$sharedData)
$PScode_to_RunNew = [PowerShell]::Create()
$PScode_to_RunNew.AddScript({
& $shareddata;
invoke-expression $shareddata;
$synchash.test = $Myvariable
})
$PScode_to_RunNew.Runspace = $RunSpaceNew
$handleNew = $PScode_to_RunNew.BeginInvoke()