To get the most out of Hyper-V it is absolutely necessary to use PowerShell commands for managing your virtual environment. By doing so you open up a lot of extra options that get you just that one step further.
While most basic settings can easily be set and adjusted in the graphical user interface, there are also a lot of really nice features that can only be managed using PowerShell as you can see in the list below.
The following list is by no means complete, but it contains some of the commands I regularly need.
For instance, you can see that by using PowerShell commands in Hyper-V you can have much more powerful networking features like NAT and VLANs. In addition you can also script and automate certain tasks in Hyper-V by using PowerShell.
Some of the commands use PowerShell piping. Piping in PowerShell is a way to execute a specific command based on the output of a previous command. In addition it can also be used to filter the output of that command, or do both.
List of commands
List virtual switches | Get-VMSwitch |
List Network adapters | Get-NetAdapter |
Add a new IP-address to an adapter (lookup InterfaceIndex with Get-Netadapter) | New-NetIPAddress -IPAddress a.b.c.d -PrefixLength ## -InterfaceIndex ## |
List all IP-addresses with an adapter | Get-NetIPAddress | Where-Object -Property InterfaceIndex -eq ## |
Create NAT network on Internal vSwitch | New-NetNat -Name <name> -InternalIPInterfaceAddressPrefix a.b.c.d/## |
List NAT networks | Get-NetNat |
Remove (all) NAT networks | Get-NetNat | Remove-NetNat |
List all VM network adapters with management from OS | Get-VMNetworkAdapter -all | ? IsManagementOS -eq $true |
Set up VLAN and trunking on Hyper-V network interface cards | Set-VMNetworkAdaptervlan |
Get VLAN information from Hyper-V network interface cards | Get-VMNetworkAdaptervlan -VMName <vmname> |
Conclusion
In conclusion, I am very aware that the list is just that, a list and nothing more. I don’t pretend to learn you anything about either PowerShell or Hyper-V with this article. Nevertheless, I think you can take advantage of this post if you use Hyper-V a lot. I myself go back to this page regularly and it saves me time not having to Google these commands again and again.
Over time, I will try to add additional commands you can use to get more productive with Hyper-V. At the same time there will be other posts on specific topics. For instance my post about creating a trunk in Hyper-V.
If you like this post or find it useful then you may also like my other posts about PowerShell.