I need to execute a PowerShell script using C#:
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"cmd.exe";
startInfo.Arguments = @"powershell -File ""C:\Users\user1\Desktop\power.ps1""";
startInfo.Verb = "runas";
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
Process process = new Process();
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
This does not work. How can I fix it?
I have a PowerShell script file and sometimes it will have arguments to pass.