PowerShell powershell = PowerShell.Create();
PSCommand command = new PSCommand();
command.AddScript("[System.Net.ServicePointManager]::ServerCertificateValidationCallback+={$true}");
是吗?
下一步是什么?使用C#来运行PowerShell脚本
PowerShell powershell = PowerShell.Create();
PSCommand command = new PSCommand();
command.AddScript("[System.Net.ServicePointManager]::ServerCertificateValidationCallback+={$true}");
是吗?
下一步是什么?使用C#来运行PowerShell脚本
从MSDN:
PSCommand command = new PSCommand();
command.AddScript(
"[System.Net.ServicePointManager]::ServerCertificateValidationCallback+={$true}"
);
PowerShell powershell = PowerShell.Create();
powershell.Commands = cmd;
var results = powershell.Invoke();
不应该'powershell.Commands = cmd;'是'powershell.Commands = command;'? –
请注意,PowerShell是IDisposable,所以它应该在一个使用块中。另外请注意,您的系统上可能有多个版本的System.Management.Automation.dll,并且您需要这些类的PowerShell 2.0或更高版本。在我的系统上,正确的文件位于C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ WindowsPowerShell \ v1.0 \ System.Management.Automation.dll - Program Files中的文件已旧。 – TrueWill
[?command.Invoke()](http://msdn.microsoft.com/en-us/library/dd144526(V = VS.85)的.aspx) –
感谢您的回复,但命令没有Invoike()方法。 –
是的,它应该是'powershell.Invoke()'完成Coincoin的建议之后。 –