Matching Windows disk to VM disk in VMWare

UPDATE 2018-02-12: The script below has some issues. I found better version here:

Those who have experience in VMWare know that there is no 1 to 1 match between VM’s disk number and the disk inside guest OS.

You can use this script to export disk mappings to grid or to a csv file:

This script is a slight modification of Conrad’s version with some improvements:

  1. Allow pipelining
  2. Use Guest’s hostname in all WMI calls instead of VM’s name (they can differ)
  3. Formatting and error checking


#// Get list of VMs that are powered on, belong to AD domain your.domain and have NICs
$vms = get-vm | ? { $_.PowerState -eq "PoweredOn" -and $_.Guest.Hostname -ilike "*.your.domain" -and $_.Guest.Nics -ne $null } | select -expand Name

#// Export the list to CSV
$vms | {path}\Get-VmDiskToWindowsDiskMapping | ConvertTo-Csv -NoTypeInformation | Out-File {path}\vms.disk.mappings.csv

#// Output the list to a Grid
$vms | {path}\Get-VmDiskToWindowsDiskMapping | Out-GridView


  1. This script requires PowerCli
  2. You must have the rights to connect to Guest OS via WMI (i.e. be an administrator or by custom rights on WMI service)
  3. The script allows pipelining
  4. In case of exception the Error field will contain the reason/message. All other fields will stay empty.
  5. The script does not show MountPoints because there is no easy way to do it via WMI (even impossible). There are some ways but they require PowerShell Remoting or PSExec which is not always possible.


Leave a Reply

Your email address will not be published. Required fields are marked *