Creating, deleting, starting, and stopping virtual machines
Creating, deleting, starting, or stopping a virtual machine is one of the most repetitive tasks that a Hyper-V administrator needs to perform, but with PowerShell, all these tasks can be scripted and made simpler to execute.
Creating a virtual machine
Creating a virtual machine is relatively simple with PowerShell using the New-VM
PowerShell cmdlet. Before you execute the commands to create a VM, let's look at Get-VM
, which gives the list of all the VMs that are present on the Hyper-V host cluster. The following command gets the nodes that are part of the Hyper-V cluster. It creates a value by property and name called ComputerName
and passes it to the Get-VM
cmdlet:
Get-ClusterNode | select @{l='ComputerName';e={$_.name}} | Get-VM
Windows Server 2012 R2 introduced the concept of generation 1 and generation 2 virtual machines, and the same can be created with PowerShell:
Then, we use the New-VM
cmdlet to create virtual...