When you expand the VMWare disk size of a virtual machine or remove a disk, it is sometimes difficult to figure out which VMware disk corresponds to a particular Windows VM disk. If there are only a few disks and they differ in size, it’s easy to find the right disk. But what if multiple VMDK (or RDM) disks of the same size or multiple SCSI virtual controllers are created for the VM? How to avoid errors and select the disk that the Windows administrator asks you to provide (or resize)?

In this article, I will show you how to map Windows disks to virtual disks (VMDK) on your VMWare VM server.

How do I get the SCSI device number in Windows and VMWare?

Open the Disk Management Console (diskmgmt.msc) in Windows (in our example, this is Windows Server 2016). The SCSI controller name and SCSI device number are not displayed in the disk list. To obtain the SCSI device number, right-click on the drive and select Properties. As you can see, the port information of the VMWare SCSI Disk Device virtual drive is displayed in the Location field of the General tab.

  • Location 160 = SCSI bus controller 0
  • Target ID 1 = SCSI device ID 1

Connect the visible data and obtain the SCSI drive address: SCSI(0:1).

Next, open the properties of the virtual machine in the VMWare vSphere client. Find the disk with the same node number of the virtual machine as the ID you have. In our example, this is the SCSI(0:1) disk 2.

If you have several virtual disks with different SCSI controllers configured in a virtual machine (up to 4 SCSI controllers with 16 disks each can be added to a virtual machine), it is quite difficult to find the SCSI device number manually. Also note that SCSI controller numbers can be different in Windows and VMWare.

How do I use PowerShell to assign a Windows disk by UUID/serial number to a VMDK?

Another way to match VMWare virtual disks with guest VM disks is to compare their unique disk IDs. In VMWare this attribute is called UUID (Unique ID) and in Windows serial number. Let’s see how to find out the UUID and serial number of a virtual disk using PowerShell. By default, the EnableUUID=TRUE volume is enabled on all VMWare virtual machines. This means that the guest operating system must see the virtual disk ID.

To get information about the disk in Windows, you can use the Storage Module commands or WMI queries. Since we still have some VM Windows Server 2008 R2 that do not have the Storage Module, we will use WMI.

Run this PowerShell command to retrieve the SCSI controller number, SCSI device number, virtual hard disk serial number (SerialNumber/UUID), hard disk size, and hard disk number in Windows :

$DiskInfo = foreach ($disk в 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.

In our example, Windows has detected three hard drives:

  • PHYSICAL0: SCSI Port 0, SCSI Target 0, Series 6000c2939b157427dadbace321ed4973
  • PHYSICAL VALVE1: SCSI port 0, SCSI target 1, serial 6000c2950ee961954909938642bb03b4
  • PHYSICAL1: SCSI port 4, SCSI target 10, serial 6000c2995fc3c4928d6650596bb02cef

Now let’s try to determine the SCSI controller numbers and disk UUIDs specified in the VMWare virtual machine settings. Use the PowerCLI console to display the VM virtual machine parameters.

VMware.VimAutomation import modules. SilentlyContinueconnect-Viserver my-esxi-server-01 kernel runtime error

$vmName=”my server-01″
$vmHardDisks = Get-VM -Name $vmName | Get-HardDisk$vmDatacenterView = Get-VM -Name $vmName | Get-View$virtualDiskManager = Get-View -Id VirtualDiskManager

$vmresults = @()
форах ($vmHardDisk в $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.nomdefichier.split(‘]’)[1].trim()
$vmresult. vmHardDiskName = $vmHardDisk. Name$vmresult. vmHardDiskSize = $vmHardDisk. CapacityGB$vmresult. vmHardDiskUuid = $vmHardDiskUuid$vmresults += $vmresult}$vmresults | ft.

This script connects to the vCenter (or ESXi) server and retrieves a list of disks for the specified VM. The result should include the DataStore name, path to the VMDK file, disk number, disk size, and UUID.

You can then manually assign the disks you see in the Windows guest operating system to VMWare virtual disks using their UUIDs.

If you have administrator privileges on the guest VM operating system, you can map Windows disks and VMWare VMDK files with a more convenient PowerShell script. The script connects the Windows guest operating system to the network, collects information about the local disks, and maps them to the VMWare VMDK.

Here is the full code of the PowerShell script:

Import-Module VMware.VimAutomation.Core -ErrorAction SilentlyContinueconnect-Viserver my-esxi-server-01$vmName = “mon-serveur-01”
$WinHostName = “mon-serveur-01.contoso.com ”
#Get VMWare$vmDisks = Get-VM -Name $vmName | Get-HardDisk$vmDatacenterView = Get-VM -Name $vmName | Get-View$virtualDiskManager = Get-View -Id VirtualDiskManager-virtualDiskManager#
Enter administrator credentials to access the guest Windows$cred
= if ($cred){$cred}else{Get-Credential}#
Get a list of Windows drives and partitions with WMI$winDisk = Get-WmiObject -Class Win32_DiskDrive -ComputerName $WinHostName -Credential $cred$diskToDriveVolume = Get-WmiObject Win32_DiskDrive -ComputerName $WinHostName -Credential $cred| % {$disk
= $_$partitions =
“ASSOCIATORS OF ” +”
{Win32_DiskDrive.DeviceID=’$($disk.DeviceID)’} ” +”
Where AssocClass = Win32_DiskDriveToDiskPartition ”
Get-WmiObject -Query $partitions -ComputerName $WinHostName -Credential $cred| % {$partition
= $_$drives =
“ASSOCIATORS OF ” +”
{Win32_DiskPartition.DeviceID=’$($partition.DeviceID)’} ” +”
Where AssocClass = Win32_LogicalDiskToPartition ”
Get-WmiObject -Query $drives -ComputerName $WinHostName -Credential $cred| % {New-Object
-Type PSCustomObject -Property @{Disk
= $disk.DeviceID
Lettre au volant = $_. DeviceID
VolumeName = $_. VolumeName}}}}#Get
serial number of the drive
foreach ($disk in $winDisk){$disk |
Add-Member -MemberType NoteProperty -Name AltSerialNumber -Value $null$diskSerialNumber = $disk.SerialNumber if
($disk.Model -notmatch ‘VMware Virtual disk SCSI Disk Device’){indien
($diskSerialNumber -match ‘^S{12}$’)){$diskSerialNumber = ($diskSerialNumber | foreach {[byte[]]$byte = $_. ToCharArray() ; $bytes | foreach {$_. ToString(‘x2’)} } ) -join ”}$disk.AltSerialNumber = $diskSerialNumber}# Find
all disks of a VM and map them
to Windows disks
based on their sequence number / UUID$diskMaps = @()
foreach ($vmDisk dans $vmDisks){$vmDiskUuid = $virtualDiskManager.queryvirtualdiskuid($vmDisk.Filename, $vmDatacenterView. MoRef) | foreach {$_.replace(‘,’).replace(‘-‘,’)}$windowsDisk = $winDisk | où {$_. SerialNumber -eq $vmDiskUuid}if
(-no $windowsDisk){$windowsDisk = $winDisk | où {$_. AltSerialNumber -eq $vmDisk.ScsiCanonicalName.substring(12,24)}}$curDiskMap = “”. | sélectionnez vmDiskDatastore, vmDiskVmdk, vmDiskName, windowsDiskIndex, vmDiskUuid, windowsDeviceID, drives, volume$curDiskMap.vmDiskDatastore = $vmDisk. filename.split(‘]’)[0].split(‘[‘)[1] $curDiskMap.vmDiskVmdk = $vmDisk. filename.split(”]’)[1].trim()
$curDiskMap. vmDiskName = $vmDisk. Name$curDiskMap. windowsDiskIndex = if ($windowsDisk){$windowsDisk.Index}else{“FAILED TO MATCH”}$curDiskMap.vmDiskUuid = $vmDiskUuid$curDiskMap.windowsDeviceID = if ($windowsDisk){$windowsDisk.DeviceID}else{“FAILED TO MATCH”}$driveVolumes = $diskToDriveVolume | where {$_.Disk -eq $windowsDisk.DeviceID}$curDiskMap.drives = $driveVolumes. DriveLetter$curDiskMap. volumes = $driveVolumes. VolumeName$diskMaps += $curDiskMap}$diskMaps = $diskMaps | sort {[int]$_. vmDiskName.split(‘ ‘)[2]}$diskMaps | ft.

The script also provides information about disk letters and disk labels in Windows.

You can now easily know which Windows disk belongs to a particular vmdk virtual disk. When virtual disks are mounted in Windows using mount points, there is no information about assigned drive letters and volume names in the output.

match windows disk to vmware hard disk,match windows disk drive mapping to virtual machine scsi controller settings,windows powershell get scsi id,which vmdk is for which hard drive,match vmdk to drive letter,map vmdk to drive letter,match virtual hard disks in virtual center with their disk labels in windows 2008,powershell mount vmdk

You May Also Like

Fix Windows Update Not Showing in Settings

To see the latest Windows 10 updates, go to Settings. In the…

Logitech Rally Camera Software Download, Manual and Review

Logitech Rally Camera, software and drivers for Windows 10, 8.1, 8, and…

How to Change Font Style in Windows 10 (& Restore Default Font)

Windows is by far the most widely used operating system on a…

Abhishek Rungta Founder And CEO Of INT (Indus Net Technologies)- Helping Clients Expand Business Digitally

Bookmark(0) Log in to favorite No bill yet? Login Abhishek Rungta is…