Find location of your VMs

Ok so now you have many, many VMs running on your Hyper-V hosts. You wanna know where are they actually running from… I mean on which SAN, which LUN or which local disk array are they running. There is no easy way to find out that information from the VMM Manager console. You can open up the properties of each and every VM and look at the config but it is not practical.

PowerShell to the rescue! Here is a small PS code snippet which will show you the information quickly.

Get-VM –ComputerName HOSTNAME1, HOSTNAME2 |
Get-VMHardDiskDrive |
Select-Object -Property VMName, ComputerName, ControllerType, Path |
Sort-Object -Property VMName |
Out-GridView -Title “Location of Virtual Disks”

I run it in Windows PowerShell ISE.

Note that you can extract info from multiple Hyper-V nodes and If required, you can easily add more information like VMId, ControllerNumber and ControllerLocation

You can extract even more information, for example if you want to see which VMs are actually running and/or if you want to output a CSV…

Get-VM -ComputerName hyperv1p,hyperv2p |
# Un-comment “state equals OFF or running” to see VMs listed in that state.
# where State -eq “OFF” |
# where State -eq “Running” |
Get-VMHardDiskDrive |
Select-Object -Property VMName, ComputerName, ControllerType, Path |
Sort-Object -Property VMName |
# Now either output to a powershell window or export to CSV (can’t do both)
# Out-GridView -Title “Location of Virtual Disks of turned off VMs”
Export-Csv .\vm-disk-location.csv

Device management using PowerShell

There are some cmdlets available for device management. They are useful on a server core type installation like Hyper-V 2012

First you need to download and import the cmdlet modules from here

Then you can run commands like get-device. However a more useful command is:

Get-Device | Sort-Object -Property Name | ft Name, DriverVersion, DriverProvider, IsPresent, HasProblem –AutoSize

More command examples are here