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?"
break
}
finally {
Write-Host "Hibernation disabled on: $name"
}
}
Onwards!
3 thoughts on “Disable hibernation on multiple Windows 2008 servers using Windows Powershell”
Comments are closed.
Recent Posts
The time is finally come! Samsung have released their Galaxy Watch 4 series of watches. It features Google Wear OS 3. and it comes in two models, being the standard model and the watch 4 classic. In...
Microsoft 365 Defender cross check with on-premises Active Directory
Recently I was reviewing the new Microsoft 365 Defender portal and I noticed that a few endpoints were missing from the device inventory. This got me thinking that it would be great if I could...

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
__CLASS : __PARAMETERS
__SUPERCLASS :
__DYNASTY : __PARAMETERS
__RELPATH :
__PROPERTY_COUNT : 2
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
ProcessId : 6128
ReturnValue : 0
Brilliant! Thanks ever so much for this, it saved my hours and worked like a dream.