Is it a simple way to get a listing over VM disks (VHDX's) in a cluster and match them with the guest VMs disk (as seen by the guest) by IDs or some other foolprof way?

I can get the virtual disk information the following way

$vm = get-vm MYVM
get-vhd -VMId $vm.VMId | ft VhdFormat,VhdType,FileSize,Size

I can get disk space and usage like this

get-WmiObject win32_logicaldisk -Computername MYVM  | ft FreeSpace,Size

I did a query on all our VMs and matched them roughly by disk size - but is there any disk GUIID or similar that are exposed to the host or guest, e.g. by way of integration services, that makes it possible to match these unequivocally?

What I am looking for is to see the size and usage from the guest OS, and compare it with the space usage and max size of the VHDX.

E.g. an empty drive, with 50GB max size, taking up 25GB on the host in an dynamic VHDX. It could even be sized to max 100GB if there was unallocated space in the disk mounted on the guest...


The reason why this will never be straightforward is probably because I am looking to match logical disks with "physical" (host VHDX) ones, and that won't always be possible if there are multiple logical/partitions mapped to one disk presented to the guest. But the challenge remains...

Found a script which seem to address the issue, but it is targeting VMWare, not Hyper-V: https://4sysops.com/archives/map-vmware-virtual-disks-and-windows-drive-volumes-with-a-powershell-script/


You do not need to match vhd to vm look at all of the members of get-vm

  get-vm | get-member

 TypeName: Microsoft.HyperV.PowerShell.VirtualMachine

Name                                MemberType    Definition                                                                                                       
----                                ----------    ----------                                                                                                       
CheckpointFileLocation              AliasProperty CheckpointFileLocation = SnapshotFileLocation                                                                    
ParentCheckpointId                  AliasProperty ParentCheckpointId = ParentSnapshotId                                                                            
ParentCheckpointName                AliasProperty ParentCheckpointName = ParentSnapshotName                                                                        
VMId                                AliasProperty VMId = Id                                                                                                        
VMName                              AliasProperty VMName = Name                                                                                                    
Equals                              Method        bool Equals(System.Object obj)                                                                                   
GetHashCode                         Method        int GetHashCode()                                                                                                
GetType                             Method        type GetType()                                                                                                   
ToString                            Method        string ToString()                                                                                                
AutomaticCriticalErrorAction        Property      Microsoft.HyperV.PowerShell.CriticalErrorAction AutomaticCriticalErrorAction {get;}                              
AutomaticCriticalErrorActionTimeout Property      int AutomaticCriticalErrorActionTimeout {get;}                                                                   
AutomaticStartAction                Property      Microsoft.HyperV.PowerShell.StartAction AutomaticStartAction {get;}                                              
AutomaticStartDelay                 Property      int AutomaticStartDelay {get;}                                                                                   
AutomaticStopAction                 Property      Microsoft.HyperV.PowerShell.StopAction AutomaticStopAction {get;}                                                
CheckpointType                      Property      Microsoft.HyperV.PowerShell.CheckpointType CheckpointType {get;}                                                 
CimSession                          Property      CimSession CimSession {get;}                                                                                     
ComPort1                            Property      Microsoft.HyperV.PowerShell.VMComPort ComPort1 {get;}                                                            
ComPort2                            Property      Microsoft.HyperV.PowerShell.VMComPort ComPort2 {get;}                                                            
ComputerName                        Property      string ComputerName {get;}                                                                                       
ConfigurationLocation               Property      string ConfigurationLocation {get;}                                                                              
CPUUsage                            Property      int CPUUsage {get;}                                                                                              
CreationTime                        Property      datetime CreationTime {get;}                                                                                     
DVDDrives                           Property      Microsoft.HyperV.PowerShell.DvdDrive[] DVDDrives {get;}                                                          
DynamicMemoryEnabled                Property      bool DynamicMemoryEnabled {get;}                                                                                 
FibreChannelHostBusAdapters         Property      System.Collections.Generic.List[Microsoft.HyperV.PowerShell.VMFibreChannelHba] FibreChannelHostBusAdapters {get;}
FloppyDrive                         Property      Microsoft.HyperV.PowerShell.VMFloppyDiskDrive FloppyDrive {get;}                                                 
Generation                          Property      int Generation {get;}                                                                                            
Groups                              Property      System.Collections.Generic.IReadOnlyList[Microsoft.HyperV.PowerShell.VMGroup] Groups {get;}                      
GuestControlledCacheTypes           Property      bool GuestControlledCacheTypes {get;}                                                                            
HardDrives                          Property      Microsoft.HyperV.PowerShell.HardDiskDrive[] HardDrives {get;}                                                    
Heartbeat                           Property      System.Nullable[Microsoft.HyperV.PowerShell.VMHeartbeatStatus] Heartbeat {get;}                                  
HighMemoryMappedIoSpace             Property      uint64 HighMemoryMappedIoSpace {get;}                                                                            
Id                                  Property      guid Id {get;}                                                                                                   
IntegrationServicesState            Property      string IntegrationServicesState {get;}                                                                           
IntegrationServicesVersion          Property      version IntegrationServicesVersion {get;}                                                                        
IsClustered                         Property      bool IsClustered {get;}                                                                                          
IsDeleted                           Property      bool IsDeleted {get;}                                                                                            
LockOnDisconnect                    Property      System.Nullable[Microsoft.HyperV.PowerShell.OnOffState] LockOnDisconnect {get;}                                  
LowMemoryMappedIoSpace              Property      uint32 LowMemoryMappedIoSpace {get;}                                                                             
MemoryAssigned                      Property      long MemoryAssigned {get;}                                                                                       
MemoryDemand                        Property      long MemoryDemand {get;}                                                                                         
MemoryMaximum                       Property      long MemoryMaximum {get;}                                                                                        
MemoryMinimum                       Property      long MemoryMinimum {get;}                                                                                        
MemoryStartup                       Property      long MemoryStartup {get;}                                                                                        
MemoryStatus                        Property      string MemoryStatus {get;}                                                                                       
Name                                Property      string Name {get;}                                                                                               
NetworkAdapters                     Property      System.Collections.Generic.List[Microsoft.HyperV.PowerShell.VMNetworkAdapter] NetworkAdapters {get;}             
Notes                               Property      string Notes {get;}                                                                                              
NumaAligned                         Property      System.Nullable[bool] NumaAligned {get;}                                                                         
NumaNodesCount                      Property      int NumaNodesCount {get;}                                                                                        
NumaSocketCount                     Property      int NumaSocketCount {get;}                                                                                       
OperationalStatus                   Property      Microsoft.HyperV.PowerShell.VMOperationalStatus[] OperationalStatus {get;}                                       
ParentSnapshotId                    Property      System.Nullable[guid] ParentSnapshotId {get;}                                                                    
ParentSnapshotName                  Property      string ParentSnapshotName {get;}                                                                                 
Path                                Property      string Path {get;}                                                                                               
PrimaryOperationalStatus            Property      System.Nullable[Microsoft.HyperV.PowerShell.VMOperationalStatus] PrimaryOperationalStatus {get;}                 
PrimaryStatusDescription            Property      string PrimaryStatusDescription {get;}                                                                           
ProcessorCount                      Property      long ProcessorCount {get;}                                                                                       
RemoteFxAdapter                     Property      Microsoft.HyperV.PowerShell.VMRemoteFx3DVideoAdapter RemoteFxAdapter {get;}                                      
ReplicationHealth                   Property      Microsoft.HyperV.PowerShell.VMReplicationHealthState ReplicationHealth {get;}                                    
ReplicationMode                     Property      Microsoft.HyperV.PowerShell.VMReplicationMode ReplicationMode {get;}                                             
ReplicationState                    Property      Microsoft.HyperV.PowerShell.VMReplicationState ReplicationState {get;}                                           
ResourceMeteringEnabled             Property      bool ResourceMeteringEnabled {get;}                                                                              
SecondaryOperationalStatus          Property      System.Nullable[Microsoft.HyperV.PowerShell.VMOperationalStatus] SecondaryOperationalStatus {get;}               
SecondaryStatusDescription          Property      string SecondaryStatusDescription {get;}                                                                         
SizeOfSystemFiles                   Property      long SizeOfSystemFiles {get;}                                                                                    
SmartPagingFileInUse                Property      bool SmartPagingFileInUse {get;}                                                                                 
SmartPagingFilePath                 Property      string SmartPagingFilePath {get;}                                                                                
SnapshotFileLocation                Property      string SnapshotFileLocation {get;}                                                                               
State                               Property      Microsoft.HyperV.PowerShell.VMState State {get;}                                                                 
Status                              Property      string Status {get;}                                                                                             
StatusDescriptions                  Property      string[] StatusDescriptions {get;}                                                                               
Uptime                              Property      timespan Uptime {get;}                                                                                           
Version                             Property      string Version {get;}                                                                                            
VirtualMachineSubType               Property      Microsoft.HyperV.PowerShell.VirtualMachineSubType VirtualMachineSubType {get;}                                   
VirtualMachineType                  Property      Microsoft.HyperV.PowerShell.VirtualMachineType VirtualMachineType {get;}                                         
VMIntegrationService                Property      System.Collections.Generic.List[Microsoft.HyperV.PowerShell.VMIntegrationComponent] VMIntegrationService {get;}  

It is extensive and includes 'harddrives' as an object property.

to see this in actions try

$vm = get-vm -name name

you can use powershells dot notation and intellisense to navigate the properties of objects so...


Similarly you can pipe all of the VM id's to get-vhd

Get-VM –VMName * | Select-Object VMid | Get-VHD

See this post for a good solution: https://social.technet.microsoft.com/Forums/en-US/8696598e-dbf6-4a47-9873-a490ecf0f737/get-storage-drives-info-for-all-vms-in-a-given-cluster?forum=winserverhyperv

Edit for clarity Here is the script from the example cited:

$ClusterVMs = Get-ClusterGroup -Cluster *clustername* | where grouptype -eq 'virtualmachine' | Get-VM
foreach ($vm in $ClusterVMs) { Get-VHD $vm.harddrives.path  | select @{N="Name";E={$VM.Name}},@{N="VHDPath";E={$VM.harddrives.path}},@{N="Capacity(GB)";E={[math]::Round($_.Size/ 1GB)}},@{N="Used Space(GB)";E={[math]::Round($_.FileSize/ 1GB)}}}

simply paste the above into powershell changing clustername to the name of your hyper-v cluster.

for a single host use the following:

$ClusterVMs = get-vm
foreach ($vm in $ClusterVMs) { Get-VHD $vm.harddrives.path  | select @{N="Name";E={$VM.Name}},@{N="VHDPath";E={$VM.harddrives.path}},@{N="Capacity(GB)";E={[math]::Round($_.Size/ 1GB)}},@{N="Used Space(GB)";E={[math]::Round($_.FileSize/ 1GB)}}}
  • Hi, but what I want to achieve is to get a view of the internal space usage of the disk as seen from the guest os, I do not believe that is possible with your proposed solution? I am sorry if my question was unclear! – grojo Jan 2 '18 at 14:45
  • it is of course possible, please try the above scripts – Sum1sAdmin Jan 2 '18 at 15:54
  • can you run this from a hyper-v host and post the output $ClusterVMs = get-vm foreach ($vm in $ClusterVMs) { Get-VHD $vm.harddrives.path | select @{N="Name";E={$VM.Name}},@{N="VHDPath";E={$VM.harddrives.path}},@{N="Capacity(GB)";E={[math]::Round($_.Size/ 1GB)}},@{N="Used Space(GB)";E={[math]::Round($_.FileSize/ 1GB)}}} – Sum1sAdmin Jan 4 '18 at 10:24
  • Sorry, I don't think it'll work, look at my update. Clearly I need something more involved to get this info - look at the exisiting solutions for vmware – grojo Jan 15 '18 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.