Bobcares

Match Windows Disks to VMWare VMDK Files – Do it with ease

by | Dec 29, 2020

Need to match Windows Disks to VMWare VMDK Files?

At Bobcares, we often handle requests from our customers to match windows disk and Virtual disks on a VMWare as a part of our Server Management Services.

Today let’s see how our Support Engineers match Windows disks and virtual disks (VMDK) on a VMWare VM.

When do we Match Windows Disks to VMWare VMDK Files?

While expanding the disk size of a VMWare virtual machine or deleting a disk, it is difficult to understand which VMware virtual disk matches the specific Windows VM disk.

When there are few disks, and they differ by their size, it is easy to find the disk we need.

But if there are several VMDK (or RDM) disks of the same size or several virtual SCSI controllers are there in a VM we will need to match the Windows disk to avoid errors.

How to Get SCSI Device Number in Windows and VMWare?

Small Computer System Interface (SCSI) number can be found with some easy and quick steps.

The steps to follow are given below:

1. First open the Disk Management console (diskmgmt.msc) in Windows.

The SCSI controller name and SCSI device number are not displayed in the list of disks.

2. Then to get the SCSI device number, we can right-click a disk and select Properties

 match windows disks to vmware vmdk files

We can see the device port for VMWare Virtual disk SCSI Disk Device is shown in the Location field of the General tab.

Location 160 = SCSI Bus Controller 0

Target ID 1 = device SCSI ID is 1

Finally by combining the information we will get the SCSI disk address: SCSI(0:1).

After that, we need to open the virtual machine properties in the VMWare vSphere Client.

And then find the disk that has the same Virtual Device Node number as the ID we have got. In our example, it is SCSI(0:1) Hard Disk 2.

 match windows disks to vmware vmdk files

If multiple virtual disks with different SCSI controllers are configured on a virtual machine.

Also, it is difficult to find the SCSI device number manually.

The SCSI controller numbers in Windows and VMWare will differ usually.

[Need assistance? We can help you!]

 

How to Match Windows Disk with VMDK by UUID/Serial Number Using PowerShell

One of the methods used by our Support Techs to map VMWare virtual disks to disks inside a guest VM is to compare their unique disk IDs

In VMWare this attribute is usually known as UUID (Unique ID), and in Windows – a Serial Number.

To get UUID and SerialNumber of a virtual disk using PowerShell.

Generally, all VMWare VMs have the disk EnableUUID=TRUE parameter enabled.

And to get information about disks in Windows, we can use the Storage module cmdlets or WMI queries.

If we have some VMs running Windows Server which does not have the Storage module, we will use WMI.

Run the following PowerShell command to get a SCSI controller number or a SCSI device number:


$DiskInfo = foreach ($disk in Get-WmiObject Win32_DiskDrive) {
[pscustomobject]@{
"DeviceID"=$disk.DeviceID;
"Caption"=$disk.Caption;
"Capacity (GB)"=[math]::Round($disk.size / 1GB,0);
"SerialNumber" =$disk.SerialNumber
"SCSIControllerNum"=$disk.scsiport;
"SCSIDeviceNum"=$disk.scsitargetid;
}
}
$DiskInfo|ft

We will see the disks as listed below:

* PHYSICALDRIVE0: SCSI Port 0, SCSI Target 0, Serial 6000c2939b157427dadbace321ed4973
* PHYSICALDRIVE1: SCSI Port 0, SCSI Target 1, Serial 6000c2950ee961954909938642bb03b4
* PHYSICALDRIVE1: SCSI Port 4, SCSI Target 10, Serial 6000c2995fc3c4928d6650596bb02cef

Then let us try to get SCSI controller numbers and UUIDs of the disks specified in the settings of the VMWare virtual machine. To view the VM settings, use the PowerCLI console.

Import-Module VMware.VimAutomation.Core -ErrorAction SilentlyContinue
connect-viserver ber-vmware1

$vmName="ber-man01"
$vmHardDisks = Get-VM -Name $vmName | Get-HardDisk
$vmDatacenterView = Get-VM -Name $vmName | Get-Datacenter | Get-View
$virtualDiskManager = Get-View -Id VirtualDiskManager-virtualDiskManager

$vmresults = @()
foreach ($vmHardDisk in $vmHardDisks)
{
$string = $vmHardDisk.Filename
$vmHardDiskUuid = ($vmHardDisk.ExtensionData.Backing.Uuid | ForEach-Object {$_.replace(' ','').replace('-','')})
$vmresult = "" | Select-Object vmHardDiskDatastore,vmHardDiskVmdk,vmHardDiskName,vmHardDiskSize,vmHardDiskUuid
$vmresult.vmHardDiskDatastore = $vmHardDisk.filename.split(']')[0].split('[')[1]
$vmresult.vmHardDiskVmdk = $vmHardDisk.filename.split(']')[1].trim()
$vmresult.vmHardDiskName = $vmHardDisk.Name
$vmresult.vmHardDiskSize = $vmHardDisk.CapacityGB
$vmresult.vmHardDiskUuid = $vmHardDiskUuid
$vmresults += $vmresult
}
$vmresults | ft

This script will connect to the vCenter (or ESXi) server and get the list of disks for the specified VM.

And the result will have  DataStore name, VMDK file path, disk number, disk size and UUID.

Finally, we can manually match the disks we see in the guest Windows OS with VMWare virtual disks by their UUIDs.

[Need assistance? We can help you!]

Conclusion

In short, we saw how to match windows disks to VMWare VMDK files. Also, we saw the easy steps followed by our Support Engineers to match this.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

3 Comments

  1. E. de Klerk

    Nice article ! If you have VMs with many disks on them (for instance Exchange mailbox servers on premise with DB mount points…) it can be useful to sort both lists in the order that they were created:

    For the VMWare Automation module code add

    $VmHardDisks = $VmHardDisks | Sort-Object Id

    For the Windows VM code add

    $DiskInfo | Sort-Object ‘SCSIDeviceNum’ | ft

    And you will have both lists sorted the same way. In the Windows VM on modern servers every new disk will get a higher SCSIDeviceNum. The same is true for the ID fiels in vCenter, which will not be sequential but will be sortable and the same order.

    Reply
  2. Rick

    Great article,

    I tried using the script on Windows 2016, but some of the properties for powershell are not available.

    SCSIControllerNum, SCSIDeviceNum, Capacity (GB) was changed to Size. Is there a workaround?

    Thanks

    Reply
    • Hiba Razak

      Hi,
      Our experts can help you with the issue.Please contact our support team via live chat(click on the icon at right-bottom).

      Reply

Submit a Comment

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

Never again lose customers to poor
server speed! Let us help you.