Manage VMs in your Hyper-V 3.0 environment

Do you know how to fully manage VMs in your Hyper-v 3.0 environment via Powershell?

Here is a list of useful commands for our day to day:

To check the host name:

To see more detailed information:
Get-vmhost | fl 

To check if there are already VMs running on the host:

Read more:

4 courses for you who want to learn Windows Server
Resolve the CREDSSP authentication error via Regedit
Fix printer error that does not appear in Windows RDP session
How to Insert a Windows Server Core into the Domain
Enabling RDP in Windows Server 2016

To check the adapters present on the host, type:

To check if there is any Virtual Switch created, just type:

Once the adapter and the type of virtual switch are defined, simply create with the following Powershell command: (A Switch called Public_Network will be created using the network card called Ethernet, where the host management will be enabled and will be of the external type):
New-VMSwitch –Name “Public_Network” –NetAdapterName “Ethernet” –AllowManagementOS $true

To create a virtual private switch called VMSwPr1 the following command could be used:
New-VMSwitch –Name “VMSwPr1” –switchtype Private

To create a new VM the simple command is:

With the above command, a new VM will be created, with 512 MB of fixed memory, a virtual processor, without a VHDx assigned using the standard Hyper-V folders. Its name will be New Virtual Machine To know the default folder where the VM is being created, just type:
Get-VMHost | select VirtualMachinePath, VirtualHardDiskPath

#Profissa: Take a professional course!
Ensure a certified course in IT and Software through the online study platform Udemy.
click here and check out all the latest technology courses!

If the command above was used to create the VM, to view the settings just type:
Get-vm -Name new * | fl *

If the idea is to create a VM from scratch with specific configurations and in specific folders we will use the same command, only with parameters:
New-VM -Name VMT01 -MemoryStartupBytes 1GB -Path d: \ vms –NewVHDPath d: \ vms \ VMT01 \ VMT01.vhdx -NewVHDSizeBytes 60GB -SwitchName Public_Network

With the Powershell command above, a new VM was created called VMT01, with 1 virtual processor (standard) and fixed memory of 1 GB. A Network Adapter was also configured using the Virtual Switch Public_Network. A new 60 GB VHDx was created (but it is dynamic - up to 60 GB) in the D: \ VMs \ VMT01 \ folder called VMT01 and the VM path was placed as D: \ VMs. (The VM creates a folder with its own name. When the VM is created, its status is turned off.
At this point it is interesting to check the status of this newly created VM:
Get-Vm -Name VMT01 | fl *

Once the VM was created, there are still some interesting commands. For this VM, before starting, let's make the following changes:
Change from 1 virtual processor to 2:
Get-VM VMT01 | Set-VMProcessor -count 2

Change from 1 GB of Fixed Memory to dynamic memory between 512 MB and 2 GB with 1 GB of initialization;
Get-VM VMT01 | Set-VMmemory –DynamicMemoryEnabled $true –MaximumBytes 2GB –MinimumBytes 512MB –StartupBytes 1GB

Add the ISO of Windows Server 2012 for installing Windows;
Set-VMDvdDrive -vmname VMT01 -Path 'D: \ ISO \ Windows Server 2012 \ Windows_Server_2012_Datacenter_VL.ISO'

#Profissa: Take a professional course!
Ensure a certified course in IT and Software through the online study platform Udemy.
click here and check out all the latest technology courses!

Once the changes are made, the VM is ready to start:
Get-VM VMT01 | Start-VM

Ready the VM is running, ready to be used.
Now suppose we are going to create another VHDx, called VMT01_D2 of 20 GB dynamic in the same folder:
New-VHD -path d: \ vms \ VMT01 \ VMT01_D2.vhdx -SizeBytes 20GB

Only the VHDx created above should be fixed. To transform from dynamic to Fixed we can use:
Convert-VHD -path d: \ vms \ VMT01 \ VMT01_D2.vhdx –DestinationPath “d: \ vms \ VMT01 \ VMT01_D3.vhdx” –VHDtype Fixed

How about adding this VHDx to the VM created with it on:
Add-VMHardDiskDrive –Vmname VMT01 –ControllerType SCSI –ControllerNumber 0 –Path d: \ vms \ VMT01 \ VMT01_D3.vhdx

To finish the basic commands:
Shut down the VM:
Get-VM VMT01 | Stop-VM
To suspend the VM:
Get-VM VMT01 | Suspend-VM
Restart the VM with OS Shutdown:
Get-VM VMT01 | Restart-VM
To check the VM snapshots:
Get-VM VMT01 | Get-VMSnapshot
To create a Snapshot of the VM:
Get-VM VMT01 | Checkpoint-VM
To rename a Snapshot:
Get-VM VMT01 | Rename-VMSnapshot –name “VMT01 - (6/18/2013 - 4:39:44 PM)” –newname SNAP1
To return a VM's Snapshot:
Get-VM VMT01 | Restore-VMSnapshot –name SNAP1
To Delete a Snapshot:
Get-VM VMT01 | Remove-VMSnapshot –name SNAP1

All Powershell commands can be found at:

Was this article helpful?

To maintain a quality standard for you, we have invested in a great hosting plan, Paid CDN, Website Optimization Plugins, etc ...

Help us to keep the project active! 

Follow the news in real time. Follow our Instagram profile..

Felipe Santos
Felipe Santos is a Cloud and Security Architect, with experience in Windows Server, Cluster, Storages, Backups Veeam and Office 365 environments.



Do you want to upgrade your career? 

Invest in yourself and get ahead! Get that dream job in 2022!