Thursday, April 21, 2011

Blog Post: Setting your machine power plan via Powershell ?repost

 

I was recently at a customer site and we found by changing the power plan on a Windows Server 2008 R2 server to High performance really gave SQL server a nice boost, I recommend making the power change on physical servers only as virtual servers can have mixed if not catastrophic results..

We measured around a 15-20% increase in noticeable performance, but that's another blog post Smile

To save time I have written a PowerShell script to set the power plan for you:

**Reposted code as the other post truncated some of the code

#Sets the machine powerplan to one of three settings:
# High performance
# Balanced
#Power saver
PARAM
(
    [Parameter(Mandatory=$true)][ValidateSet("High performance", "Balanced", "Power saver")]
    [string]$PreferredPlan
)

function SetPowerPlan([string]$PreferredPlan)
{
    Write-Host "Setting Powerplan to $PreferredPlan"
    $guid = (Get-WmiObject -Class win32_powerplan -Namespace root\cimv2\power -Filter "ElementName='$PreferredPlan'").InstanceID.tostring()
    $regex = [regex]"{(.*?)}$"
    $newpowerVal = $regex.Match($guid).groups[1].value

    # setting power setting to high performance
    powercfg -S  $newpowerVal
}

#set Preferred powerplan
SetPowerPlan $PreferredPlan

Lily Allen Emmanuelle Chriqui Anna Faris Lil Kim Kelly Ripa

No comments:

Post a Comment