使用C#运行PowerShell脚本

Ste*_*ack 4 c# powershell

PowerShell powershell = PowerShell.Create();
PSCommand command = new PSCommand();
command.AddScript("[System.Net.ServicePointManager]::ServerCertificateValidationCallback+={$true}");
Run Code Online (Sandbox Code Playgroud)

是对的吗?
下一步是什么?

Coi*_*oin 6

来自MSDN:

PSCommand command = new PSCommand(); 
command.AddScript( 
    "[System.Net.ServicePointManager]::ServerCertificateValidationCallback+={$true}"
); 

PowerShell powershell = PowerShell.Create();
powershell.Commands = cmd;

var results = powershell.Invoke();
Run Code Online (Sandbox Code Playgroud)