views:

68

answers:

1

I'm writing an application that can run PowerShell scripts which I'd like to be run on the application's thread. The following code:

Runspace runspace = RunspaceFactory.CreateRunspace();  // create Powershell runspace
runspace.ThreadOptions = PSThreadOptions.UseCurrentThread;

Works and compiles fine on Windows 7, but can't be compiled in XP due to these errors:

 'System.Management.Automation.Runspaces.Runspace' does not contain a definition for 
    'ThreadOptions' and no extension method 'ThreadOptions' accepting a first argument of type
    'System.Management.Automation.Runspaces.Runspace' could be found (are you missing a using 
    directive or an assembly reference?)


    The name 'PSThreadOptions' does not exist in the current context

Is this issue related to powershell v1 vs v2? I have the .NET 4 install on the XP machines (and VS 2010). Thanks!

+3  A: 

From here:

"This property is introduced in Windows PowerShell 2.0."

Michael Todd
Thanks! Now to see if I can figure out a work around... :)
Evan
Can you install PowerShell 2.0 via the Microsoft Management Framework for XP (http://support.microsoft.com/kb/968929)? Note that this has nothing to do with .NET 4.
Keith Hill
@Keith, thanks a ton - that took made the above code work!
Evan