I want to set "High Performance" powerplan on multiple server machines. I've the following script which is running fine when I execute this on the servers one by one.
Set-PowerPlan "High performance"
function Set-PowerPlan {
[CmdletBinding(SupportsShouldProcess = $True)]
param (
[ValidateSet("High performance", "Balanced", "Power saver")]
[ValidateNotNullOrEmpty()]
[string] $PreferredPlan = "High Performance"
)
Write-Host "Setting power plan to `"$PreferredPlan`""
$guid = (Get-WmiObject -Class Win32_PowerPlan -Namespace root\cimv2\power -Filter "ElementName='$PreferredPlan'").InstanceID.ToString()
$regex = [regex]"{(.*?)}$"
$plan = $regex.Match($guid).groups[1].value
powercfg -S $plan
$Output = "Power plan set to "
$Output += "`"" + ((Get-WmiObject -Class Win32_PowerPlan -Namespace root\cimv2\power -Filter "IsActive='$True'").ElementName) + "`""
Write-Host $Output
}
How to pass a list of servers to this script so that the power plan is set on all servers recursively?