0

I'm trying to run a powershell script in C# console application, but i've getting a trouble..

The code is simple:

ProcessStartInfo startInfo = new ProcessStartInfo
                {
                    FileName = "powershell.exe",
                    Arguments = $"-NoProfile -ExecutionPolicy Bypass -file \"{File_ScriptTestTrust}\"",
                    CreateNoWindow = true,
                    WindowStyle = ProcessWindowStyle.Hidden,
                    RedirectStandardOutput = true,
                    RedirectStandardError = true,
                    UseShellExecute = false,
                };

                var run = new Process
                {
                    StartInfo = startInfo,
                };

                run.Start();

                run.WaitForExit();
                string s = run.StandardOutput.ReadToEnd();

And my script is:

nltest /sc_query:domain.com

Unfortunately, I'm stuck in this error:

"nltest : The term 'nltest' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again...

I've trying to figure out this error for 2 days and nothing. In powershell I run just fine, but when run with visual studio, get error.

Luiz Palte
  • 121
  • 1
  • 2
  • 12

0 Answers0