How to manage Hyper-v virtual machines (VM) from the command line..

This article applies to This article does not apply to This article is not tied to any specific product. Not all product versions are identified in this article.

Symptoms

Article Summary: This article provides information on how to manage Hyper-V Virtual Machines (VM) from the command line.


Integration Services provides the virtual equivalent of drivers and firmware for the child partition Virtual Machine (VM) to communicate with the Parent Partition and the network. Reviewing the Hyper-V hypervisor architecture reveals the underpinnings of the hypervisor are not different then the mapping of drivers to a system bus.

For more information on Hyper-V architecture, refer to the MSDN Library Article: Hyper-V Architecture

Below you will see commands to control the Virtual Machines from the command line. PowerShell puts you control. In addition, this document addresses how to manage on Server 2008 or 2012 with the Hyper-V role installed. If you have 2012 installed you already have many features built into the Windows 2012 release using import-module Hyper-V. See some examples at the Dell Community site.
You may still want to use the script for its robust functionality.

  1. Download the PowerShell feature from the PowerShell Management Library for Hyper-V.
  2. Install  the PowerShell feature in Server Manager-> Features->Add Features.
  3. Verify that .NET 3.5 sp1 is installed. It contains the required .NET 2.0 version, which is needed by the script.
    This download is also available at the PowerShell Management Library for Hyper-V.
  4. Open PowerShell (as an Administrator) and run Set-ExecutionPolicy unrestricted.
  5. Import the module before using it. i.e. import-module c:\hyperv\hyperv.psd1.
  6. Run the install.bat file (as an Administrator) and answer a few questions.

    Note: There is an error that occurs on opening the shell which can be ignored, as this script was originally used with Server Core. The User's Guide documentation is very good and a necessary part of using the many commands available. It is also a download at the CodePlex site.

Below are some basic commands:

  • Get-VM , Get-VM –Server name ,
  • Get-VMsummary, Get-VMSummary DNS –Server Main
  • start-VM, stop-VM
  • Get-VMMemory –VM servername -server hypervhostname
  • Get-VMMemory | Get-Member –MemberType *Property | Select-Object Name
  • Get-VMMemory | FT VMElementName, Address, AllocationUnits
  • Get-VMMemory | ConvertTo-HTML | Out-File C:\hyperv\report.html (Invoke-Expression c:\hyperv\report.html will open the file)
  • Get-VMMemory | ConvertTo-CSV | Out-File C:\hyperv\report.csv
  • Set-VMMemory –VM "myvm" –Memory 4.0GB –Server hypervhostname
  • Get-VM –Name "myvm%"- returns a list of all vms with myvm in the title
  • Get-VM –Name "myvm%" | Set-VMMemory –Memory 2.0GB - sets the memory of all machines with that name in the title
  • Get-VMnic
  • Set-VMCPUCount "myvm" 2 - changes the number of virtual cpu
  • Get-VM | Get-VMMemory | out-file -filepath C:\myvm.txt""

For an exhaustive list of commands, download the Codeplex PDF.
For a complete list of commands available for Server 2012, refer to the Microsoft TechNet Article Windows PowerShell Support for Windows Server 2012 or Hyper-V Cmdlets in Windows PowerShell.   

Affected Products

Servers, PowerEdge
Article Properties
Article Number: 000138557
Article Type: Solution
Last Modified: 21 Feb 2021
Version:  3
Find answers to your questions from other Dell users
Support Services
Check if your device is covered by Support Services.