Call x86 PowerShell Script from an x64 C # application

I looked through several Questions and did not find anything similar to apply to my situation (from what I could say).

I have an x64 application (I cannot change the architecture to meet the design requirements) and it needs to call PowerShell Script in the x86 architecture.

var runspaceConfiguration = RunspaceConfiguration.Create(); var runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration); runspace.Open(); var pipeline = runspace.CreatePipeline(); var myCommand = new Command(@"MY-COMMAND"); myCommand.Parameters.Add("Path", @"C:\"); pipeline.Commands.Add(myCommand); return pipeline.Invoke(); 

If anyone can give me an idea of ​​how I can start an x86-PowerShell session with C #, I would really appreciate it.

Edit: I will update this with the corrected code as soon as I remove the details.

+4
source share
1 answer

Run the script in your x64 C # application that runs the task to execute the 32-bit script. Be sure to use the -RunAs32 switch on Start-Job . This will require PowerShell 2.0 or higher.

 pipeline.Commands.AddScript("Start-Job -Scriptblock { My-Command.exe -Path C:\ } -Name MyCommandJob -RunAs32"); 

You will need to get the results using Receive-Job -Name MyCommandJob .

+8
source

All Articles