Managing the VM state involves stopping and starting, or pausing and resuming, a VM. You can also save and restore, as shown in this recipe.
This recipe uses the PSDirect
VM created in the Creating a virtual machine recipe. This recipe assumes the PSDirect
VM is stopped when you start this recipe. If this VM is running, then first stop it using the Stop-VM
cmdlet.
Stop-VM -Name PSDirect -WarningAction SilentlyContinue Get-VM -Name PSDirect
Start-VM -VMName PSDirect Wait-VM -VMName PSDirect -For IPAddress Get-VM -VMName PSDirect
PSDirect
VM:Suspend-VM -VMName PSDirect Get-VM -VMName PSDirect
Resume-VM -VMName PSDirect Get-VM -VMName PSDirect
Save-VM -VMName PSDirect Get-VM -VMName PSDirect
Start-VM -VMName PSDirect Get-Vm -VMName PSDirect
Restart-VM -VMName PSDirect -Force Get-VM -VMName PSDirect
Wait-VM -VMName PSDirect -For IPaddress Get-VM -VMName PSDirect
Stop-VM -VMName PSDirect -TurnOff Get-VM -VMname PSDirect
This recipe shows you how to manage VM state. In step 1, you view the properties of the VM, which is not running. As you can see from the screenshot, the PSDirect
VM is turned off and is not running (and has an uptime of 00:00:00
), as follows:
With step 2, you start the PSDirect
VM and retrieve the VM's status, which looks like this:
Next, in step 3, you suspend the PSDirect
VM, which looks like this:
In step 4, you resume the PSDirect
VM, which looks like this:
With step 5, you save a VM and view the status, like this:
With step 6, you start the saved PSDirect
VM and view the VM's details, which looks like this:
With step 7, you forcibly shut down the VM, which looks like this:
In step 8, you wait until the PSDirect
VM is up and running to re-view the VM's status, which looks like this:
With step 2, you start the VM and retrieve the VM's status. Next, in step 3, you suspend then resume a VM.
With step 3 and step 4, you suspend then resume the PSDirect
VM. While the VM is suspended, the VM is not active and therefore receives and sends no network traffic. The VM's memory is maintained, as is the current state, and the VM can be resumed at any moment.
In step 6 you save the PSDirect
VM. When you save a VM, Hyper-V saves the VM's memory to disk and the VM's virtual disks are not used. Saving a VM is similar to pausing it, except that with a saved VM, all the VM's memory is written to disk then released.
In step 7, you perform a forced shutdown of the PSDirect
VM. This is equivalent to pulling the power from a running computer then restarting it. When you do this, all VM state is lost, and it is possible to introduce disk corruption due to data being still in memory and not written to disk prior to the power off. While Windows and the most-used Windows filesystems (NTFS and ReFS) are fairly resilient to errors, you should avoid hard shutdown if possible.
18.217.150.123