- Disable dynamic memory on the VM - it's incompatible with hibernation
- Run the following PowerShell script on the host:
Param (
[string]$VmName,
[bool]$Enable = $true
)
# To modify, machine must be off
$Vm = Get-VM -Name $VmName
$Vm | Stop-VM -Force -WarningAction Ignore
$wmiComputerSystem = gwmi -namespace root\virtualization\v2 -query "select * from Msvm_ComputerSystem where ElementName= '$VmName'"
$wmi_vsSettingData = $wmiComputerSystem.GetRelated("Msvm_VirtualSystemSettingData","Msvm_SettingsDefineState",$null,$null, "SettingData", "ManagedElement", $false, $null)
Write-Output ("Before: EnableHibernation = " + $wmi_vsSettingData.EnableHibernation)
# $wmi_vsSettingData.EnableHibernation = $Enable # Doesn't work - says The property 'EnableHibernation' cannot be found on this object
# So, need to munge XML ourselves
[xml]$vsSettingsDataXml = $wmi_vsSettingData.gettext(1)
$EnableHibernationNodes = $vsSettingsDataXml.SelectNodes("/INSTANCE/PROPERTY[@NAME='EnableHibernation']")
$EnableHibernationNodes[0].VALUE=$Enable.ToString()
$wmi_vsSettingDataMgmt = Get-WmiObject -Namespace "root\virtualization\v2" -Class Msvm_VirtualSystemManagementService
$job = $wmi_vsSettingDataMgmt.ModifySystemSettings($vsSettingsDataXml.OuterXml)
Notes:
- Tested on Windows 10 1903, both host and guest
- Once you run this, you can do the following in the VM:
powercfg -a
shows that Hibernate is available on the system
powercfg -h on
works
- Power Settings => Additional power settings => Choose what to power button does => Now you can check "Hibernate - Show in Power menu", and you'll get hibernate in the Start=>Power menu.
Shutdown /h
will hibernate
- After you hibernate and restart the machine, you won't be able to connect to it using "Enhanced Session". This is resolved after a full restart of the VM.