Managing Hyper-V with PowerShell

Managing Hyper-V with PowerShell

Windows Server 2012 solved PowerShell managment issues

There's no doubt that PowerShell is Microsoft's preferred server management tool heading into the future—and for many good reasons. For starters, with Windows Server 2012, there's a new capability for running servers without a local GUI, enabling them to have less overhead and require less patching. Plus, PowerShell commands can be scripted, providing a way to automate both routine and complex tasks. (See also, "Understanding Windows Server 2012 Hyper-V Networking Changes" and "Q: How can I check the version of Windows PowerShell installed on my machine?")

Don't get me wrong—I'm a big fan of graphic interfaces and they are great for interactively performing ad hoc management tasks and graphic interfaces make it easy to use a system. The graphical UI is what made Windows popular in the first place. However, performing a complex task using the graphical interface can be time consuming and error prone because there's many steps—opening the door for unintended errors.

Avoid Unintended Errors

PowerShell scripting is a great answer to unintended errors because it enables you to automate operations using fixed scripts that you can pass variables into. Scripts don't change until you change them and they execute much quicker than you can manually perform a given task. 

Managing Hyper-V with PowerShell wasn't really practical until the release of Windows Server 2012. Ironically, while VMware offered their own set of cmdlets for managing vSphere, Microsoft didn't have a PowerShell offering for Hyper-V. Sure, there's PowerShell integration capabilities for System Center Virtual Machine Manager (VMM), but a lot of businesses don't use VMM. There's also a PowerShell management library available from CodePlex. However, most organizations didn't want to begin standardizing on CodePlex when they knew that Microsoft had to address this situation at some point in the future.

With Windows Server 2012, Microsoft tackled the PowerShell management issues head-on. Windows Server 2012 added 2,000+ new management cmdlets and over a 160 of those cmdlets are for natively managing Hyper-V. For an overview of the new Hyper-V cmdlets in Windows Server 2012 check out Hyper-V Cmdlets in Windows PowerShell.

New Windows Server 2012 Hyper-V cmdlets

The new Windows Server 2012 Hyper-V cmdlets use the standard PowerShell verb-noun command structure making them pretty easy to learn. PowerShell cmdlets start with verbs that describe the action you want to take. Examples include ADD, START, STOIP, GET, SET, ENABLE, DISABLE, NEW, and REMOVE. The Hyper-V PowerShell cmdlets use two basic  noun prefixes that identify what Hyper-V component you're working with: VM (Virtual Machine) and VHD (Virtual Hard Disk). Examples of some Hyper-V PowerShell management commands that create a new VM called MyVM and then start and stop the VM are shown below: 

PS >New-VM -Name MyVM –MemoryStartupBytes 1GB -NewVHDPath c:\MSVMs\MyVM.vhd -NewVHDSizeBytes 40GB
PS >Start-VM –Name MyVM 
PS >Stop-VM –Name MyVM

New tools like the Windows Server 2012 Integrated Scripting Environment (ISE) make it easier to get started using PowerShell. In addition, when you're just getting started, PowerShell's Get-Help command can also help make you more productive right away. For instance, to learn about using the New-VM cmdlet you could enter: 

PS >Get-Help New-VM –Detailed
PS >Get-Help New-VM -Examples

If you're using Windows Server 2012, now's the time to dive into PowerShell management for Hyper-V.

Related: Manage Hyper-V with PowerShell

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.