Read on:
Beginners’ Guide for Microsoft Hyper-V: Overview of Hyper-V Part 1
Beginners’ Guide for Microsoft Hyper-V: How to Install Microsoft Hyper-V Using Server Manager – Part 2
Beginners’ Guide for Microsoft Hyper-V: How to Install Microsoft Hyper-V with PowerShell – Part 3
Beginners Guide for Microsoft Hyper-V: How to Install Microsoft Hyper-V in Windows Server Core – Part 4
Beginners Guide for Microsoft Hyper-V: Remote Management of Hyper-V – Part 5
Beginners Guide for Microsoft Hyper-V: How to Install Hyper-V Server – Part 6
Beginner’s Guide for Microsoft Hyper-V: What is Azure Stack HCI – Part 7
Beginner’s Guide for Microsoft Hyper-V: Windows Admin Center Hyper-V Management – Part 8
Beginner’s Guide for Microsoft Hyper-V: Configuration of Hyper-V Networking Best Practices – Part 9
Beginner’s Guide for Microsoft Hyper-V: Hyper-V Storage Best Practices and Configuration – Part 10
Beginner’s Guide for Microsoft Hyper-V: How to build a Virtual Lab with Hyper-V – Part 11
One of the enticing and powerful capabilities of Microsoft Hyper-V is the deep PowerShell integration with the solution. IT admins juggling many tasks need the ability to leverage automation to carry out daily administration tasks and achieve management and configuration at scale. As a Hyper-V beginner, gaining the skills necessary to use PowerShell for Hyper-V configuration and management is essential. Let’s look at the best Hyper-V PowerShell cmdlets for beginners and see how these can be used.
Why use PowerShell with Hyper-V?
We have mentioned the value of PowerShell in managing and configuring Microsoft Hyper-V. It allows automating many day-to-day processes with Hyper-V management and configuration for Hyper-V admins. It also allows quickly pulling information from the Hyper-V environment in a meaningful way.
PowerShell is not Hyper-V specific and is built into modern Windows client and server versions, allowing admins quick and easy access to the PowerShell command line. In addition, PowerShell is a modular scripting framework. It enables vendors to add modules that extend PowerShell’s reach and functionality. For example, Microsoft has created a module for Hyper-V installed when you add the Hyper-V role.
As you can see below, when you add the Hyper-V role, the Hyper-V GUI management tools and the Hyper-V Module for Windows PowerShell are installed along with the Hyper-V role.
When we think about the question, why use PowerShell with Hyper-V, it is a great idea for many reasons. These include:
- It is freely available as part of the Hyper-V role – It is installed by default, and there are no additional components or installation required
- It saves time – When you want to query the Hyper-V environment, you can certainly do this using the Hyper-V Manager. However, for expediency and time, as well as the power of pulling information, PowerShell is the superior tool for this use case
- It can be used for configuration management – When you have many Hyper-V hosts and virtual machines, using PowerShell allows scripting configurations. It allows configurations and settings to be implemented in an automated way without the possibility of human error. This capability ensures the Hyper-V hosts are identically configured, maintained, and managed
- It can be used when the GUI isn’t available – If you are running Hyper-V on a Windows Server Core installation, you can run PowerShell cmdlets on the Windows Server Core server where you don’t have access to the Hyper-V Manager GUI
The best Hyper-V cmdlets for beginners
What are some of the best Hyper-V cmdlets for beginners looking to learn Hyper-V management and configuration? These include the following:
- Get-VM
- Get-VMHost
- Get-VMHostCluster
- Start-VM
- Stop-VM
- New-VM
- Checkpoint-VM
- New-VMSwitch
- Measure-VM
- New-VHD
1. Get-VM
The Get-VM cmdlet gets the virtual machines from one or more Hyper-V hosts and allows querying information about the virtual machines.
2. Get-VMHost
The Get-VMHost cmdlet allows pulling and querying information about the Hyper-V host that houses virtual machines in the Hyper-V environment.
3. Get-VMHostCluster
When you run Hyper-V as a clustered role on Windows Server Failover Cluster services, you can use the Get-VMHostCluster PowerShell cmdlet to pull information about the Hyper-V cluster.
4. Start-VM
As the name implies, the Start-VM cmdlet starts a Hyper-V virtual machine on a Hyper-V host or Hyper-V cluster.
5. Stop-VM
Like the Start-VM cmdlet, the Stop-VM cmdlet allows controlling the power state of the Hyper-V virtual machine. With the Stop-VM cmdlet, you can power off Hyper-V virtual machines.
6. New-VM
The New-VM cmdlet is an excellent PowerShell cmdlet for Hyper-V beginners. It allows creating a new Hyper-V virtual machine from the command line, saving tremendous time and effort using the GUI, especially if you are creating VMs in bulk.
7. Checkpoint-VM
Checkpoints are akin to “snapshots” with other technologies like VMware. Using a Checkpoint, you can roll a virtual machine back to a specific point in time.
8. New-VMSwitch
Creating virtual networking in Hyper-V allows admins to create new virtual switches. These connect virtual machines to various physical networks in the environment and allow quickly creating isolated networks for lab environments.
9. Measure-VM
The Measure-VM cmdlet allows Hyper-V admins to gather resource utilization data and create reports for Hyper-V virtual machines in the environment.
10. New-VHD
The New-VHD cmdlet allows Hyper-V admins to create new Hyper-V virtual disks that can be attached to Hyper-V virtual machines.
These are just a few of the Hyper-V cmdlets available. For a full listing of the available Hyper-V PowerShell cmdlets, see the official Microsoft documentation here: Hyper-V Module | Microsoft Learn
Wrapping Up
PowerShell provides powerful capabilities and features in managing, configuring, and provisioning Hyper-V hosts and virtual machines. The Hyper-V Manager GUI is a great tool that is easy to use and allows quickly managing your Hyper-V hosts and virtual machines, but it does not scale very well or allow bulk changes in the environment to many hosts and virtual machines.
Using PowerShell, Hyper-V administrators can roll out configuration changes to multiple hosts, virtual machines, virtual networks, storage, and other configurations in a short time. It also provides a robust configuration management solution, allowing Hyper-V hosts and virtual machine configurations to be standardized.
PowerShell is a relatively easy scripting language to understand, even for beginners. No additional software needs to be installed in modern Windows clients and servers, and the Hyper-V PowerShell module is installed by default when the Hyper-V role is added. It makes using PowerShell for Hyper-V management a quick win for administrators to manage and configure Hyper-V at scale in the enterprise.
Beginners learning Hyper-V do well to start using and learning ‘PowerShell with Hyper-V’ early on to get familiar with Hyper-V. It will pay dividends when beginners transition into junior and senior roles, managing larger production Hyper-V environments.
Follow our Twitter and Facebook feeds for new releases, updates, insightful posts and more.