以下のPowerShellスクリプトを使用して、サーバーの電源プランをハイパフォーマンスモードに設定しています。問題は、サーバー名をテキストファイル(Servers.txt)に渡しても、スクリプトを実行しているサーバーだけに変更が加えられていることです。私はforeach
ループを使ってサーバーリストを繰り返しましたが、まだ運がありません。私はどこにロジックが不足しているかわからない、誰かがこれを手伝うことができます。前もって感謝します。PowerShellスクリプトが正常に動作しない(foreachループ)
$file = get-content J:\PowerShell\PowerPlan\Servers.txt
foreach ($args in $file)
{
write-host "`r`n`r`n`r`nSERVER: " $args
Try
{
gwmi -NS root\cimv2\power -Class win32_PowerPlan -CN $args | select ElementName, IsActive | ft -a
#Set power plan to High Performance
write-host "`r`n<<<<<Changin the power plan to High Performance mode>>>>>"
$HighPerf = powercfg -l | %{if($_.contains("High performance")) {$_.split()[3]}}
$CurrPlan = $(powercfg -getactivescheme).split()[3]
if ($CurrPlan -ne $HighPerf) {powercfg -setactive $HighPerf}
#Validate the change
gwmi -NS root\cimv2\power -Class win32_PowerPlan -CN $args | select ElementName, IsActive | ft -a
}
Catch
{
Write-Warning -Message "Can't set power plan to high performance, have a look!!"
}
}
こんにちはvonPryz、システム名を渡すかもしれないと思いますそれを修正しました。 –