Reputation: 385
I need to run windows powershell script from my programm. To do that, I just start powershell process with a string arg which contains script body itself:
Process.Start("powershell.exe", "my script body..");
and it works. But I also need to pass some args to script. It should look like :
Process.Start("powershell.exe", "some args my script body..");
Upvotes: 0
Views: 565
Reputation: 385
Working solution :
Process.Start("powershell.exe", "-noexit -command &{write-host $args[0]} arg1Value arg2Value");
Upvotes: 0
Reputation: 26120
from the doc, you should be able to do something like :
process.Start("powershell.exe","-noprofile -file c:\temp\test.ps1 TEST -noexit")
where TEST is the argument passed to the script
edit after re reading your question :
process.Start("powershell.exe","-noprofile -command {write-host $args[0] } -args 'test'")
Upvotes: 2