ドメイン サーバーから実行され、ドメイン サーバー上で「機能する」スクリプトがあります。
作業は、保存された PSsession を使用して呼び出しコマンドで呼び出されるスクリプトブロック内のジョブに分割されます。
結果は、ログ ファイル名に日時スタンプを含むログ ファイルにドメイン サーバーに記録されます。
ここで、作業が行われるリモートに常駐する必要がある別のログを追加する必要があります。ログ名の形式には、日付と時刻のスタンプも含める必要があります。
私の問題は、ログの名前を各ジョブに渡して、同じファイルに書き込むようにすることです。-ArgumentList、@args、および $args をいじってみましたが、エラーなしで実行できますが、何もしないため、ログファイル名を正しく渡していません。
以下は、スクリプトの構造を非常に簡略化したものです。
Start-Job を別のスクリプト ブロックにネストするのは間違いですか? 成功/失敗と特定のポイントをキャプチャするために、一意のログ ファイル名をこれらの多数のスクリプト ブロックに渡すにはどうすればよいでしょうか?
#log file names, ps session and other variables declared here
$DoDomainWorkScriptBlock = {
Try {
start-job -name DoDomainWorkjob -scriptblock{
$command = "C:\Program Files\someprogram\someprogram.exe"
& $command -f someargs
If ($? -ne "True") {Throw 'Do work failed’}
" Do non-domain work job completed. "
}
} Catch {$Error[0] | Out-File $ErrorLog -Append}
}
#other jobs nested in other scriptblocks like the one above here
Invoke-Command -session $RemoteSession -scriptblock $DoDomainWorkScriptblock | Out-File $DomainProgressLog -Append
Invoke-Command -session $RemoteSession -command{Wait-Job -name DoDomainWorkjob } | Out-File $DomainProgressLog -Append
Invoke-Command -session $RemoteSession -command{Receive-Job -Name DoDomainWorkjob } | Out-File $DomainProgressLog –Append
#invoke start, wait, and receive job commands for the other jobs