Mastering Windows Server 2016 Hyper-V

(Romina) #1
        Cmdlet  Move-VM             2.0.0.0
Cmdlet New-VM 2.0.0.0
Cmdlet Remove-VM 2.0.0.0
Cmdlet Rename-VM 2.0.0.0
Cmdlet Repair-VM 2.0.0.0
Cmdlet Restart-VM 2.0.0.0
Cmdlet Resume-VM 2.0.0.0
Cmdlet Save-VM 2.0.0.0
Cmdlet Set-VM 2.0.0.0
Cmdlet Start-VM 2.0.0.0
Cmdlet Stop-VM 2.0.0.0
Cmdlet Suspend-VM 2.0.0.0
Cmdlet Wait-VM 2.0.0.0

I cover many of these cmdlets throughout the book, related to specific types of
activity. In this section, I cover some commands that are useful for quickly getting a
view of your Hyper-V environment.


To view the basic information about a Hyper-V host, use Get-VMHost -ComputerName
server | Format-List, and most attributes returned can be modified using the Set-
VMHost cmdlet.


To view all virtual machines running on a Hyper-V host, use the Get-VM cmdlet. A key
feature of PowerShell is the ability to pipe information from one cmdlet to another.
This enables comprehensive feedback and intelligent, automated sets of actions,
which is why PowerShell management is a much better option for performing actions
across multiple servers with virtual machines. For example, I may want to export all
virtual machines that are currently turned off. The first cmdlet gets all virtual
machines, the second part identifies the VMs in the Off state, and then only those
VMs are passed to the final cmdlet, which exports them.


Get-VM -ComputerName |
where-object {$_.State -EQ "Off"} | Export-VM -Path D:\Backups


Likewise, I had a folder full of virtual machines I wanted to import into a Hyper-V
server. This is easy with PowerShell. The following code looks for XML files (which is
the format for virtual machine configurations) and then imports:


Get-ChildItem e:\virtuals*.xml -recurse | Import-VM


In another case, I wanted to configure all virtual machines that were set to start
automatically not to start if they were running when the Hyper-V server shut down.
That’s easy with PowerShell:


Get-VM | Where-Object {$_.AutomaticStartAction -eq "StartIfRunning"} |`
Set-VM -AutomaticStartAction Nothing -AutomaticStopAction ShutDown


SCVMM also has its own PowerShell module. Provided it’s installed, it can be loaded
using this command:


Import-Module virtualmachinemanager

Free download pdf