Recovering Virtual Machines in Hyper-V Server 2012 R2: Part 5

Doctor Scripto

Summary: Adjust virtual machine settings by using only Windows PowerShell. Hey, Scripting Guy! Question Hey, Scripting Guy! I need to adjust the settings for some virtual machines on a Hyper-V box. How can I do that without using the GUI? —TM Hey, Scripting Guy! Answer Hello TM, Honorary Scripting Guy, Sean Kearney here—filling in for our good friend Ed.

Note  This is the fifth post in a series. To review, see:

There is probably a strong misconception of “If I don’t have the GUI, I can’t manage Hyper-V.” But this really isn’t the case when you have Windows PowerShell. When we have a series of virtual machines imported, we can use Windows PowerShell cmdlets to manage these virtual machines. For example, we might want to ensure that our virtual domain controller always starts automatically:

GET-VM ‘CONTOSO-DC’ | SET-VM –automaticstartaction Start Or maybe I want to power up all of the virtual machines:

GET-VM | START-VM (By the way, with a lot of virtual machines, this could get a little slow.) If we need to find out which of those virtual machines are running:

GET-VM | Where { $_.State –eq ‘Running’ } We also can adjust the memory configuration of these virtual machines. For example if I want to adjust the memory of a virtual machine:

SET-VM ‘CONTOSOVM1’ –memorystartupbytes 512MB Or perhaps we made some mistakes and we need to get rid of a virtual machine:

GET-VM ‘CONTOSOVM1’ | REMOVE-VM But perhaps I need to make a more deliberate removal? I always used to hate using the GUI to delete a virtual machine that I wanted to permanently remove because I would have to clean up afterwards. We can do this easily with Windows PowerShell:

$DiskList=GET-VM ‘CONTOSOVM1’ | GET-VMHardDiskDrive | Select-object Path


$DiskList | Remove-item $_ -force

REMOVE-VM ‘CONTOSOVM1’ In fact, we presently have over 178 Hyper-V cmdlets to manage the environment by using only Windows PowerShell. So there you have it.  If you are running the free version of Hyper-V Server 2012 R2, there is very little stopping you from recovering virtual machines in it—even it if you don’t have the GUI to work with. And remember, you can still join this virtual machine to a domain, set it up in a high availability Hyper-V cluster, and implement VHD replication! Pop into this weekend as more Windows PowerShell excitement continues! I invite you to follow the Scripting Guys on Twitter and Facebook. If you have any questions, send email to, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace. Sean Kearney, Honorary Scripting Guy and Windows PowerShell MVP


Discussion is closed.

Feedback usabilla icon