문제

I am writing a short c# program which execute a powershell script test.ps1. The code is the following :

 Runspace runspace = RunspaceFactory.CreateRunspace();
    runspace.Open();
    Pipeline pipeline = runspace.CreatePipeline();
    pipeline.Commands.AddScript(scriptText);
    pipeline.Commands.Add("Out-String");
    Collection<psobject> results = pipeline.Invoke();
    runspace.Close();

there is a psexec in the test.ps1 but when I run the c# program I get : "psexec is not recognize as a cmdlet ...", but when I launch my script in powershell it works. Something wrong with the runspace ? (I have tried also psexec.exe and c:\windows\system32\psexec.exe)

도움이 되었습니까?

해결책

When you download PStools you extract some files. Put those files in C:\Windows\System32 AND in C:\Windows\Systemwow64.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top