Question

I'm trying to develop some tool in C# which is using PowerShell. However, I have to use different powershell then this one which is used by default when creating Runspace, I mean this one:

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe

Is it possible to force Runspace to use different (customized) version of powershell?

The problem with the standard version of powershell doesn't have many commands, such like "Open-Device" and "Close-Device".

Thank you in advance

Was it helpful?

Solution

I think you are missing the difference between the PSH runtime and the host. The host provides services (Write-Host, transscripts, ...) to the runtime. Hence ISE doesn't do transcripts because it doesn't implement that service.

With a runspace you just get the core PSH runtime plus any snapins/modules you load into it. Depending how Open-Device and Close-Device are implemented you might be stuck. If they are implemented by a snapin or module (that your custom host automatically loads) then just load the necessary components. If those cmdlets depend on something the host itself implements then you'll need to look at running a separate process.

(Increasingly having to use a custom host should be seen as poor form as it won't work with jobs, remoting, and (I suspect) workflows.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top