我需要从 C# 启动一个 powershell 脚本并在 pipeline.Invoke() 上获取 PSSSecurityException
AuthorizationManager 检查失败。
我的代码:
RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
using (Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration))
{
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
Command scriptCommand = new Command(scriptfile);
pipeline.Commands.Add(scriptCommand);
pipeline.Invoke();
}
问题
- 我怀疑我需要设置 PSCredential。但是我不能提示它,所以我必须在代码中处理它。这可以以安全的方式完成吗?(事实并非如此)