Start a Hyper-V VM ^
To start a Hyper-V VM, use the following command:
Start-VM -VMName "Kali Linux" -Passthru | Get-VM
This command starts the Kali Linux VM. By default, the Start-VM cmdlet does not return any output. So, I used the -PassThru parameter to generate the output and pass it down the pipeline, and then used the Get-VM cmdlet to return the status of the VM. You can see that the VM state is now Running.
Disable secure boot ^
Note that if you actually try to boot the VM from the DVD drive to start the OS installation, it will fail. This is because the Generation 2 VMs have "Secure Boot" enabled by default.
Secure boot is a security feature available in the UEFI firmware that is designed to ensure that an operating system's loading utility is safe and has not been tampered with. To install Kali Linux or any other Linux distro in the Hyper-V VM, you might need to disable the secure boot feature of the VM. If you're going to install Windows 10 or 11, you can keep secure boot enabled.
To disable secure boot for a VM in Hyper-V, make sure the VM is stopped, and then run the following command:
Set-VMFirmware -VMName "Kali Linux" -EnableSecureBoot Off
This command disables the secure boot for our Kali Linux VM. You can now go ahead and deploy the operating system on the VM. I am not going to cover the OS deployment steps in this guide.
Stop a Hyper-V VM ^
To stop a Hyper-V VM, use the following command:
Stop-VM -VMName "Kali Linux"
This command shuts down the VM through the guest operating system. If the VM is not responding or there is some other issue, use the -Force parameter with the Stop-VM cmdlet to forcefully stop the VM. Please remember that forcefully stopping a VM could result in data loss. To save the VM state and stop it, use the -Save parameter as shown below:
Stop-VM -VMName "Kali Linux" -Save
This command saves the VM state before stopping it. When you start the VM again, it resumes from the saved state.
The Stop-VM cmdlet also supports the -TurnOff parameter, which is equivalent to unplugging the power cord from the system.
So, what's the difference between the -Force and -TurnOff parameters?
The -Force parameter is safer since it invokes the guest operating system's shutdown functionality. It usually gives the VM five minutes so that the end user can safely close the running programs and save the data.
The -TurnOff parameter, on the other hand, is equivalent to unplugging the power cord from the system, which forcefully turns off the VM. The user gets no time to close the apps and save the data, which could result in data loss, disk errors, or even disk failures. Use the -TurnOff parameter only as a last resort when -Force does not work.