2 つのプロセスをリモートで強制終了し、いくつかのフォルダーを削除し、サービスをアプリケーションとして起動するスクリプトを作成しています。最終的にこれは複数のサーバーに対して実行されるように展開されますが、現在、単一のサーバーに対してテストしています。リモート サービスを起動する最後のステップを除いて、すべてがうまく機能します (サービスとして実行されるとの互換性の問題により、-cl 引数を使用してアプリケーションとして実行されます)。アプリケーションはスクリプトを介して起動しますが、スクリプトが次のステップに進むとすぐにシャットダウンします。私はまったく初心者なので、かなり掘り下げてきましたが、解決策を見つけることができませんでした。新しい実行空間でプロセスを起動する必要があるようですが、それを行うための適切な noob ガイドを見つけることもできません。
また、スクリプトは、ローカライズされてマシン上で実行された場合と同じように実行されます。
これが私が持っているものです
$a = Get-ChildItem "\\TestMachine\c$\DataFiles"
$pass = cat "C:\cred.txt" | convertto-securestring
$mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist "username",$pass
if ($a.Count -gt 10)
{
Invoke-Command -ComputerName TestMachine -cred $mycred -scriptBlock {stop-process -name TestProcess -force -EA SilentlyContinue}
Invoke-Command -ComputerName TestMachine -cred $mycred -scriptBlock {stop-process -name Winword -force -EA SilentlyContinue}
Get-ChildItem -Path \\TestMachine\c$\WordDocs -Recurse -EA SilentlyContinue | Where-Object {$_.PsIsContainer} | Remove-Item -Recurse -Force -EA SilentlyContinue
Invoke-Command -ComputerName TestMachine -cred $mycred -scriptBlock {Start-Process "C:\Program Files (x86)\Test\TestUploadManager\TestUploadManager.exe" -Verb Runas -ArgumentList -cl}
echo "Success: TestMachine Was successfully reset"
}
else
{
echo "Failed: Reset was not necessary"
}
exit