我正在尝试远程执行传递对象参数的 powershell 脚本。我已经成功地做到了这一点,但现在我只想启动脚本,断开我的远程会话并让 powershell 脚本继续在远程机器上执行。不幸的是,我一直无法做到这一点。
到目前为止,这是我的代码,它成功运行了远程 powershell 脚本,但是如果我处理我的会话,powershell 脚本也会停止执行:
PowerShell ps = PowerShell.Create();
ps.Runspace = _runspace;
ps.AddCommand(scriptPath);
if (scriptParameters != null)
{
foreach (var parameter in scriptParameters)
{
ps.AddParameter(parameter.Key, parameter.Value);
}
}
ps.Invoke();
即使断开远程会话,我如何才能启动 .ps1 脚本并让它继续运行?