#requires -version 3.0 Function Get-VHDSummary { <# .Synopsis Get Hyper-V VHD Information .Description Get a summary report of all associated VHDs with their respective virtual machines. This requires the Hyper-V PowerShell module. .Example PS C:\> Get-VHDSummary VMName : CHI-Client02 Path : D:\VHD\Win7_C.vhd Type : Dynamic Format : VHD SizeGB : 25 FileSizeGB : 21 VMName : CHI-Client02 Path : C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\CHI-Client2-Swap.vhdx Type : Dynamic Format : VHDX SizeGB : 4 FileSizeGB : 1 VMName : Win2012-01 Path : D:\VHD\Win2012-01_340B1F8F-FFFB-4DCD-9B3A-7819D8BCE3C2.avhdx Type : Differencing Format : VHDX SizeGB : 40 FileSizeGB : 2 .Example PS C:\> get-vhdsummary | sort Type | format-table -GroupBy Type -Property VMName,Path,*Size* .Example PS C:\> get-vhdsummary | Copy-item -destination Z:\VHDBackup .Example PS C:\> get-vhdsummary | measure-object -property FilesizeGB -sum .Link Get-VM Get-VHD #> Param() Get-VM | Select-Object -expandproperty harddrives | Select-Object -property VMName,Path, @{Name="Type";Expression={(Get-VHD -Path $_.Path).VhdType}}, @{Name="Format";Expression={(Get-VHD -Path $_.Path).VhdFormat}}, @{Name="SizeGB";Expression={((Get-VHD -Path $_.Path).Size)/1GB -as [int]}}, @{Name="FileSizeGB";Expression={((Get-VHD -Path $_.Path).FileSize)/1GB -as [int]}} } #end function <# This is a variation that is more efficient and a better PowerShell function. #> Function Get-VHDSummary2 { Param() #get all virtual machines $vms=Get-VM foreach ($vm in $vms) { Write-Host "Getting drive info from $($vm.name)" -foregroundcolor Cyan #get the hard drives foreach virtual machine $vm.HardDrives | ForEach-Object { #a VM might have multiple drives so for each one get the VHD $vhd=Get-VHD -path $_.path <# $_ is the hard drive object so select a few properties and include properties from the VHD #> $_ | Select-Object -property VMName,Path, @{Name="Type";Expression={$vhd.VhdType}}, @{Name="Format";Expression={$vhd.VhdFormat}}, @{Name="SizeGB";Expression={($vhd.Size)/1GB -as [int]}}, @{Name="FileSizeGB";Expression={($vhd.FileSize)/1GB -as [int]}} } #foreach } #foreach vm } #close function