1
我想通過PowerShell scriptblock遠程啓動Zookeeper和Solr。 然後我看到進程是在遠程機器上創建的(通過檢查Zookeeper的端口2181)。在腳本完成時它將被終止。 即使完成後我該如何保持這種狀態?如何在遠程PowerShell腳本完成後保持進程存活?
以下代碼在腳本完成時停止遠程進程。 script.ps1
做了很多事情,包括啓動Zookeeper和Solr asJob。
int iRemotePort = 5985;
string strShellURI = @"http://schemas.microsoft.com/powershell/Microsoft.PowerShell";
string strAppName = @"/wsman";
WSManConnectionInfo ci = new WSManConnectionInfo(
false,
machineName,
iRemotePort,
strAppName,
strShellURI,
new PSCredential(userName, secure));
Runspace runspace = RunspaceFactory.CreateRunspace(ci);
runspace.Open();
using (PowerShell ps = PowerShell.Create())
{
session.Log(@"c:\temp\script.ps1 -serverID " + counter + " -copySolrConfig $" + status + " -currentHost \"" + machineName + "\" -IP_PORT_List \"" + String.Join(", ", machineWithPort) + "\"");
ps.Runspace = runspace;
ps.AddScript(@"c:\temp\script.ps1 -serverID " + counter + " -copySolrConfig $" + status + " -currentHost \"" + machineName + "\" -IP_PORT_List \"" + String.Join(", ", machineWithPort) + "\"");
var results = ps.Invoke();
foreach (var result in results)
{
session.Log(result.ToString());
}
}
runspace.Close();
如需幫助,請提供代碼:顯示您的代碼。 –