Hyper-V How To: Find the right Hyper-V Cmdlet

Jamesone’s excellent PowerShell Management Library for Hyper-V includes a Hyper-V cmdlet documentation PDF file that helps you  chunk all the things you can do with Hyper-V using PS, for example, the following list of cmdlets parsed by function:

Admin functions not specific to Hyper-V

  • Test-Admin Tests if the Powershell session is privileged
  • Get-ScriptPath Returns the path to the script
  • Choose-List Allows the user to select a item from a list view
  • Choose-Tree Allows the user to select a item from a tree view
  • Out-Tree Prevents items in a tree view
  • New-zip Creates a new .ZIP archive file
  • Add-ZIPContent Adds files to a .ZIP archive file
  • Copy-ZIPContent Copies files to from .ZIP archive file
  • Get-ZIPContent Gives a lists of items in a ZIP archive file

Conversion functions

  • Convert-DiskIDtoDrive Converts a drive ID number into it’s associated drive letters
  • Convert-VMState Converts th number for a VM state into the state’s name

Functions for Hyper-V Servers

  • Get-VMHost Gets a list of Hosts running Hyper-V from Active directory

Functions for checking WMI jobs created through Hyper-v

  • Test-WMIJob Checks on the state of job – can wait until it completes

Virtual Machine

  • Choose-VM Allows the user to select VMs from a list
  • Get-VM Retuns WMI objects representing VMs
  • New-VM Creates a new VM
  • Set-VM Sers the properties of an Existing VM
  • Remove-VM Deletes a VM
  • Export-VM Invokes Hyper-Vs export process
  • Import-VM Invokes Hyper-Vs import process
  • Ping-VM Ping FQDNs found via KVP exchange integration component
  • Shutdown-VM Shuts down a VM’s OS cleanly via shutdown integration compoent
  • Start-VM Starts a VM or restarts a saved one
  • Stop-VM Powers down a VM without asking the OS to shutdown first
  • Suspend-VM Puts the VM into a saved state
  • Set-VMState Called by Start, stop and suspend VM set the requested states
  • Get-VmBackupScript Gets a script for backing up one or more VMs
  • Get-VMByMACaddress Discovers a VM from its MAC address
  • Get-VMJPEG Gets a JPEG image of the currect VM screen
  • Test-VMHeartBeat Tests the responses from the heartbeat integration component
  • Get-VMSettingData Returns the Setting data object for the VM
  • New-VMConnectSession Launches a VM connect session to a VM.

VM Memory

  • Get-VMMemory Returns the amount of memory assigned to a VM
  • Set-VMMemory Sets the amount of memory assigned to a VM

VM Processors

  • Get-VMCPUCount Gets the number and weighting of Processors assigned to VMs
  • Set-VMCPUCount Sets the number of Virtual Processors assigned to VMs
  • Get-VMProcessor Gets active Virtual Processors and their load data

VM Disk Controllers

  • Get-VMDiskController Gets an IDE or SCSI controller (IDE controllers can’t be changed)
  • Add-VMSCSIcontroller Adds a synthetic SCSI controller to a VM
  • Remove-VMSCSIcontroller Removes a synthetic SCSI controller from a VM

Hard disk and DVD drive objects

  • Add-VMDRIVE Connects a Harddisk drive or DVD drive to a controller
  • Remove-VMDRIVE removes a Hard disk drive or DVD drive from a controller
  • Get-VMDriveByController Gets the drives attached to a controller

Hardisk and DVD disk Image object

  • Add-VMDisk Mounts a DVD or Hard disk image into a Drive
  • Get-VMDisk Gets a list of Virtual disk images in use
  • Set-VMDisk changes the disk image attached to a drive
  • Get-VMDiskByDrive Gets the VM disk image attached to a drive
  • Add-VMNewHardDisk Attaches a new virtual hard disk image to a new drive

Virtual Hard disk image files

  • Get-VhdDefaultPath Gets the Default path Used by Hyper-v for VHD files
  • Get-VHDInfo Gets information about a VHD, such as its parent, size on disk
  • New-VHD Creates a new VHD file
  • Test-VHD Tests that a VHD can be mounted, and any parent is mountable
  • Compact-VHD Compacts a dynamic VHD file to save space on the host
  • Convert-VHD Changes a VHD from one type to another
  • Expand-VHD Expands the size of a virtual hard disk
  • Merge-VHD Merges the a child VHD with its parent to form a new disk
  • Mount-VHD Makes the VHD file appear as a local disk on the host
  • UnMount-VHD Reverses the mount process so the VHD can be used by a VM

VM Floppy Disk

  • New-VFD Creates a new floppy disk image file
  • Add-VMFloppyDisk Mounts the Floppy disk in the floppy drive of a VM
  • Get-VMFloppyDisk Returns information about the mounted floppy disk
  • Remove-VMFloppyDisk Ejects any floppy disk from the drive of a VM

Resource Allocation Settings data objects

-
New-VMRasd Creates objects used by other functions to describe VM components

Serial Port Objects

-
Get-VMSerialPort Returns information about serial

  • Set-VMSerialPort Maps Serial ports on a VM to Named Pipes

Ethernet Cards

  • Add-VMNic Adds a Nic to a VM
  • Choose-VMNic Allows the user to select a NIC attached to a virtual machine
  • Get-VMNic Returns information about network cards
  • Remove-VMNic Removes a NIC from a VM
  • Set-VMNICAddress Sets the MAC address for a NIC
  • Set-VMNICSwitch Connects a NIC to a virtual Switch
  • Get-VMNicport Gets the Switch port attached to a NIC
  • Get-VMnicSwitch Returns the Switch a NIC is connected to

Ethernet Switches

  • Choose-VMExternalEthernet Allows the user to choose a host network card
  • New-VMExternalSwitch Creates a Virtual Switch connect to a host network card
  • New-VMInternalSwitch Creates a Virtual Switch accessible to VMs and the Host
  • New-VMPrivateSwitch Creates a Virtual Switch accessible to VMs
  • Choose-VMSwitch Allows the user to choose a virtual switch
  • Get-VMSwitch Returns information about virtual switches
  • New-VMSwitchPort Defines a new port on a virtual switch

Key value Pairs

  • Get-VMKVP Gets Key/value pair information sent to the Host by Virtual Machines
  • Add-VMKVP Adds a Key/value pair to the list sent to VMs by the host
  • Remove-VMKVP Removes a Key/value pair from the list sent to VMs by the host

Snapshots

  • Apply-VMSnapshot Applies a snapshot to a VM
  • Choose-VMSnapshot Allows the user to choose a snapshot
  • Get-VMSnapshot Gets information about snapshots
  • Get-VMSnapshotTree Formats the view of Snapshots as a tree
  • New-VMSnapshot Creates a new snapshot of a VMRemove-VMSnapshot Deletes a snapshot or tree of snapshots
  • Rename-VMSnapshot Renames a snapshot
  • Update-VMSnapshot Deletes a snapshot, and creates a new one with same name

Did I mention the Management Library is free-as-in-beer?

Want to know more about James? See https://blogs.technet.com/tonyso/archive/2009/06/24/a-day-in-the-life-of-an-it-pro-evangelist-james-o-neill.aspx

For more Hyper-V scripts, see the Official Scripting Guys Forum.