Disable hibernation on multiple Windows 2008 servers using Windows Powershell

By default hibernation is disabled on Windows 2008 server machines. However, a file called “hiberfil.sys” (equally sized to the amount of memory in the machine) is created in the root of the system volume.
On a machine with 2GB of memory, this is not a big issue. However I discovered this on a VM with 12GB of memory.. *auch*
After some google’ing around I found out that there’s a way to get rid of this “hiberfil.sys”, the following Microsoft KB article gives you more information about this: http://support.microsoft.com/kb/920730/en-us
This command disables hibernation and also get’s rid of the hiberfil.sys file:

powercfg.exe /h off

But what if we wanted to repeat this task for let’s say 30-40 servers? Do it by hand? No way, Powershell to the rescue!
Here’s the script I came up with, enjoy:

# Ask for credentials used to do remote WMI.
$cred    	= Get-Credential DOMAIN\account

# Filter used for active directory query. Only 2008 server machines.
$strFilter 	= "(&(objectClass=computer)(operatingSystem=Windows *2008*))"

$objDomain 	= New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"

$colResults = $objSearcher.FindAll()

# Loop through list of servers.
foreach ($objResult in $colresults)
	$objItem = $objResult.Properties
	$name = $objItem.name[0]

	Write-Host "Disabling hibernation on: $name"

	try {
		invoke-wmimethod -cred $cred -path win32_process -name create -argumentlist "powercfg.exe /h off" -ComputerName $name
	catch {
		Write-Host "Failed to disable hibernation on: $name, no permission or server down?"
	finally {
		Write-Host "Hibernation disabled on: $name"


You can leave a response, or trackback from your own site.

3 Responses to “Disable hibernation on multiple Windows 2008 servers using Windows Powershell”

  1. Albert Widjaja says:

    Thank you for sharing this great script man, however how can I view the current power scheme like the following command does:

    C:\>powercfg -l

    Existing Power Schemes (* Active)
    Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced) *
    Power Scheme GUID: 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c (High performance)
    Power Scheme GUID: a1841308-3541-4fab-bc81-f71556f20b4a (Power saver)

    I tried using the modified script:

    invoke-wmimethod -cred $cred -path win32_process -name create -argumentlist “powercfg.exe -l” -ComputerName $name

    but it doesn’t show up anything useful ?

    __GENUS : 2
    __RELPATH :
    __DERIVATION : {}
    __SERVER :
    __PATH :
    ProcessId : 6128
    ReturnValue : 0

  2. IT Questions says:

    IT Questions and answers…

    […]Disable hibernation on multiple Windows 2008 servers using Windows Powershell | Maartendamen's blog[…]…

  3. James Elliott says:

    Brilliant! Thanks ever so much for this, it saved my hours and worked like a dream.

Leave a Reply