複数のサーバーからCPU使用率を取得するには、以下のスクリプトを実行しています。以下のスクリプトが永久にスクロールする場所、つまりコンソール出力はありません。だから私は特定の時間の後に殺すJobコマンドを使用しています。しかし、このコードを実行しようとすると、エラー以下になってしまいます。個々のPowerShellコマンドの制限
個々のPowerShellコマンドの制限時間を設定する方法はありますか?
$ServerList = ("xyz","abc")
foreach ($computername in $ServerList) {
$timeout = 30
$job = Start-Job -ScriptBlock {
Get-WmiObject Win32_Processor -ComputerName $using:computername |
Measure-Object -Property LoadPercentage -Average |
Select Average
}
Wait-Job -Job $job -Timeout $timeout
Stop-Job -Job $job
Receive-Job $job
Remove-Job -Job $job
}
Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again. + CategoryInfo : InvalidData: (:) [Get-WmiObject], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetWmiObjectCommand
[タイムアウト付きコピー項目](の可能性のある重複http://stackoverflow.com/questions/38623767/copy-item- with-timeout) –
'Start-Job -Computer $ computername -Scriptblock {Get-WmiObject Win32_Processor | ...; ...} -Timeout ... ' –
リプレイのおかげで@Angar Wiechers以下のコードは出力を表示しません:$ computername =" XYZ " $ timeout = 300 $ job = Start-Job -computername $ computername -Scriptblock {Get-WmiObject win32_processor | Measureオブジェクト - プロパティLoadPercentage - 平均|平均を選択} 待機ジョブ-Job $ジョブ - タイムアウト$タイムアウト 停止ジョブ-Job $ジョブ 受信ジョブ-Job $ジョブ ジョブを削除-Job $ジョブ – Raj