Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to invoke a powershell script string in a separate process but seems like I am not getting any argument passed to the script. Is there a way to invoke powershell script in a separate process

C#
private static void InvokeScript(int arguments)
     {
         Process p = new Process();
         p.StartInfo.FileName = "powershell.exe";
         p.StartInfo.Arguments = String.Format("{0}\"\"{1}\"\"", update, arguments);
         p.StartInfo.RedirectStandardOutput = true;
         p.StartInfo.RedirectStandardError = true;
         p.StartInfo.UseShellExecute = false;
         p.Start();
         var output = p.StandardOutput;
         var error = p.StandardError;
         string result = output.ReadToEnd();
         string errorstring = error.ReadToEnd();
         p.WaitForExit();
     }



C#
 private const string update = @"
try
{    
    return $($args.count)
}
catch
{
    return $_.Exception.Message
}";
Posted
Updated 18-Dec-14 10:44am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900