Export Virtual Machine Harddisk details from Windows Server 2012 R2 Hyper V Cluster

One of the key responsibility of Hyper V Administrator to keep track of Storage utilization and clean up of stale Virtual Hard Disk, sharing a Powershell script to list down the Virtual Machine.

Script output will create CSV file with VMName, HVHOST and Virtual Hard disk path as example below.

logon to one of the Hyper V Cluster node and run it with powershell.

VMName ComputerName Path
TestVM HVHOSt1 C:\ClusterStorage\Volume2\Virtual Machines\TestVM\Virtual Hard Disk\TestVM.VHDX
#Export Virtual Machine Harddisk details from Windows Server 2012 R2 Hyper V Cluster#
#======================================================================================#

#Start-Process powershell -Verb runAs Administrator
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process PowerShell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
#Display more data in console

$FormatEnumerationLimit = 20

#Get the Hyper V cluster

$Cluster=Get-cluster

#Report File output name as cluster name
$H=get-cluster

#Powershell to export the VM Disk details

Get-VM –ComputerName (Get-ClusterNode –Cluster $Cluster) | Get-VMHardDiskDrive | ft VMName,ComputerName,Path -AutoSize >c:\$H.csv

#Thank you & Best of luck, for visiting www.sanjars.com