I was looking at a WPF/Powershell article MS Powershell blog
WPF & PowerShell – Part 1 ( Hello World & Welcome to the Week of WPF ) When ever I try the 3rd Example
# Create a runspace to run Hello World
$rs = [Management.Automation.Runspaces.RunspaceFactory]::CreateRunspace()
$rs.ApartmentState, $rs.ThreadOptions = “STA”, “ReuseThread”
$rs.Open()
# Reference the WPF assemblies
$psCmd = {Add-Type}.GetPowerShell()
$psCmd.SetRunspace($rs)
$psCmd.AddParameter("AssemblyName", "PresentationCore").Invoke()
$psCmd.Command.Clear()
$psCmd = $psCmd.AddCommand("Add-Type")
$psCmd.AddParameter("AssemblyName", "PresentationFramework").Invoke()
$psCmd.Command.Clear()
$psCmd = $psCmd.AddCommand("Add-Type")
$psCmd.AddParameter("AssemblyName", "WindowsBase").Invoke()
$sb = $executionContext.InvokeCommand.NewScriptBlock(
(Join-Path $pwd "HelloWorld.ps1")
)
$psCmd = $sb.GetPowerShell()
$psCmd.SetRunspace($rs)
$null = $psCmd.BeginInvoke()
I get an error...
Method invocation failed because [System.Management.Automation.PowerShell] doesn't contain a method named 'SetRunspace'
I ran a $psCmd | gm
and there isn't a method called 'SetRunspace'.
What gives???