我正在使用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通過系統的名稱,由於一噸,我已經糾正了它。 –