2
votes

I was wondering if there is a way to stipulate which version of Powershell is initialised (32bit\64bit) on a 64bit windows 2008 server using c# and the the system.automation namespace?

The reason for this is I have created a ps1 script that uses a com object which will only work in a 32bit Powershell environment.

I am not aware of a way to specify 32bit\64bit during runspace creation but may be wrong. Any thoughts or suggestions?

Thanks

1
Since it all lives in your process (the Runspace doesn't create a separate PowerShell process, I guess) it should be the bitness of your application. You can restrict it to 32 bit if the COM object won't work otherwise. - Joey
Was wondering if it would be that easy. Will give it a go tomorrow. Thanks - Niall Gray

1 Answers

1
votes

Changing your application's configuration from "Any CPU"/"x64" to "x86" is definitely the simplest way to make sure the Powershell script runs in 32-bit. You can check it with a script with these contents:

if ([System.IntPtr]::Size -eq 8) {'64-bit'} else {'32-bit'}

Configuring the Runspace to be 32-bit running in a 64-bit application may be possible, but it may also be more trouble than it's worth.