Add-Type –assemblyName PresentationFramework #CREATE HASHTABLE AND RUNSPACE FOR GUI $syncHash = [hashtable]::Synchronized(@{}) $newRunspace =[runspacefactory]::CreateRunspace() $newRunspace.ApartmentState = "STA" $newRunspace.ThreadOptions = "ReuseThread" $newRunspace.Open() $newRunspace.SessionStateProxy.SetVariable("syncHash",$syncHash) $code = { #Build the GUI [xml]$xaml = @"