Hyper-V can be managed using the GUI or … using PowerShell! Before starting, just make sure that Hyper-V role is installed with the following command:
PS> Get-WindowsFeature -Name Hyper-V Display Name Name Install State ------------ ---- ------------- [X] Hyper-V Hyper-V Installed
If Hyper-V role is not installed, run the “Install-WindowsFeature” cmdlet:
Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart
Do not forget to include the “-IncludeManagementTools” parameter because it will install the PowerShell module for Hyper-V.
Be careful, this command will force a reboot.
Now you can easily get the list of Hyper-V cmdlets by using the following command:
Get-Command –Module "Hyper-V"
Output will be something like that:
PowerShell let you accomplish most of the tasks that you can accomplish with the GUI.
Listing Hyper-V Hosts and Virtual Machines
Let’s see two examples. first, I will list my Hyper-V host and then I will list its VMs.
1- If you want to display the local Hyper-V host:
PS> Get-VMHost Name LogicalProcessorCount MemoryCapacity(M) VirtualMachineMigrationEnabled ---- --------------------- ----------------- ------------------------------ HYPV01 24 122869,796875 False
2- If you want to display all the VMs:
PS> Get-VM Name State CPUUsage(%) MemoryAssigned(M) Uptime Status ---- ----- ----------- ----------------- ------ ------ DeployIIS1 Running 0 4096 5.17:23:06 Operating normally IISSysprep Saved 0 0 00:00:00 Operating normally TemplateSQL Saved 0 0 00:00:00 Operating normally testDB1 Saved 0 0 00:00:00 Operating normally TestIIS01 Running 0 4096 5.16:22:33 Operating normally testIIS4 Running 0 4096 5.17:23:19 Operating normally testIIS5 Running 0 4096 5.17:22:29 Operating normally testsql02 Running 0 4096 5.17:22:57 Operating normally testsql03 Off 0 0 00:00:00 Operating normally testsql04 Running 0 4096 5.17:22:32 Operating normally testsql07 Running 0 4096 5.17:22:28 Operating normally
Many cmdlets let you display some information about your Hyper-V environment. You can list these cmdlets with the following command:
Get-Command Get-VM*
If you need further information about these cmdlets, you can use the “Get-Help” cmdlet.
Thanks for reading! You can follow me on Twitter @PrigentNico