I have the following Powershell script :
param(
[string] $Source ,
[string] $Target ,
[string] $UserId
)
Set-Location "C:\My folder"
& "C:\Program Files\nodejs\node.exe" "index.js" $Source $Target $UserId
I need to execute it from a C# application, so I have this code:
var process = new Process();
string parameters = string.Format(" -Source {0} -Target {1} -UserId {2} ", Source, Target, UserName);
process.StartInfo.FileName = @"C:\windows\system32\windowspowershell\v1.0\powershell.exe";
process.StartInfo.Arguments = "\"&'" + ScriptName + "'\" ";
process.Start();
string s = process.StandardOutput.ReadToEnd();
process.WaitForExit();
This works in invoke my script, but I don't know how to pass the parameters that I have in the variables.
I already tried using Runspace runspace = RunspaceFactory.CreateRunspace(); but this way doesn't execute my script.
C:\windows\system32\windowspowershell\v1.0\powershell.exe -command "get-date -year 2010"then Powershell starts up and runsget-date -year 2010. Try something like that. I.E., set the arguments to-command "get-date -year 2010"(substituting your script and your script arguments)ScriptName? Also, the argument line is unclear... Check out this article on how to call the exe:learn.microsoft.com/en-us/powershell/module/…