1

リモート マシンには Vesper.exe というアプリケーションがあります。私が今していることは、powershell セッションを使用してマシンにリモートでログインすることです。

要件: リモート マシンでアプリケーションを起動する必要があり、powershell スクリプトの実行が終了した後もアプリケーションを実行し続ける必要があります。

私は2つの方法を試しましたが、要約は次のとおりです。

  • Invoke-Command: このコマンドレットを使用してアプリケーションを起動すると、スクリプトが停止し、アプリケーションが最終的に停止するまで待機します
  • Start-Process: このコマンドレットを使用すると、アプリケーションは実行を開始しますが、すぐに終了します。これを見つけた理由は、コマンドレットRemove-PSSessionを使用していたのに、 Exit-PSSessionを使用してリモート マシンでプロセスを維持する必要があることを発見したためです。しかし、これに関する問題は、ビルドの実行が完了すると (または PowerShell ウィンドウを閉じると)、リモート マシン上のアプリケーションが停止することです。ここで何をすべきかわかりません。

以下は、powershell コードです。

# Create a new session on the remote machine with the above credentials
try {
    $newsession = New-PSSession -ComputerName $loadvm -Credential $loadvm_credentials
    Write-Host "Connected successfully..."
} catch [Exception] {
    echo "Error while connecting to the remote machine", $_.Exception.GetType().FullName, $_.Exception.Message
    exit 1
}
try {
    Invoke-Command -Session $newsession -Scriptblock {
      Write-Host "Cd'ing and starting Vesper on"
      cd C:\vesper_cpt
      Start-Process -file Vesper.exe -ArgumentList "-auto"
    } -ErrorAction Stop
} catch [Exception] {
    echo "Error while running the remote command", $_.Exception.GetType().FullName, $_.Exception.Message
    Remove-PSSession $newsession
    exit 1
}

Exit-PSSession
4

1 に答える 1