Match Windows Disks to VMWare VMDK Files

When increasing the disk measurement of a VMWare digital machine or deleting a disk, typically it’s onerous to perceive which VMware digital disk matches the precise Windows VM disk. If there are few disks and so they differ by their measurement, it’s simple to discover the disk you want. But what to do if a number of VMDK (or RDM) disks of the identical measurement or a number of digital SCSI controllers have been created for a VM? How to keep away from errors and choose the disk a Windows administrator asks you to broaden (or shrink)?

In this text we’ll see how to match Windows disks and digital disks (VMDK) on a VMWare VM.

Contents:

  • How to Get SCSI Device Number in Windows and VMWare?
  • How to Match Windows Disk with VMDK by UUID/Serial Number Using PowerShell?

How to Get SCSI Device Number in Windows and VMWare?

Open the Disk Management console (diskmgmt.msc) in Windows (in our instance, it’s Windows Server 2016). The SCSI controller title and SCSI system quantity are usually not displayed within the checklist of disks. To get the SCSI system quantity, right-click a disk and choose Properties. As you possibly can see, the details about the system port for VMWare Virtual disk SCSI Disk Device is proven within the Location area of the General tab.

  • Location 160 = SCSI Bus Controller zero
  • Target ID 1 = system SCSI ID is 1

Join the info you see and get the SCSI disk deal with: SCSI(zero:1).

windows get scsi disk number - bus number, target id

Then open the digital machine properties in your VMWare vSphere Client. Find the disk that has the identical Virtual Device Node quantity because the ID you’ve got. In our instance, it’s SCSI(zero:1) Hard Disk 2.

Get VMWare Virtual Disk SCSI ID

If a number of digital disks with completely different SCSI controllers are configured on a digital machine (you possibly can add up to four SCSI controllers with 16 disks every to a digital machine), it’s fairly difficult to discover a SCSI system quantity manually. Also please observe that SCSI controller numbers in Windows and VMWare could differ.

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

Another means to map VMWare digital disks to disks inside a visitor VM is to examine their distinctive disk IDs. In VMWare this attribute is named UUID (Unique ID), and in Windows – a Serial Number. Let’s see how to get UUID and SerialNumber of a digital disk utilizing PowerShell.

By default, all VMWare VMs have the disk EnableUUID=TRUE parameter enabled. It signifies that a visitor OS should see digital disk IDs.

To get the details about disks in Windows, you need to use the or WMI queries. Since we nonetheless have some VMs operating Windows Server 2008 R2 that don’t have the Storage module, we’ll use WMI.

To get a SCSI controller quantity, a SCSI system quantity on it, a serial variety of a digital disk (SerialNumber/UUID), a disk measurement and disk quantity in Windows, run this PowerShell command:

$DiskInfo = foreach ($disk in Get-WmiObject Win32_DiskDrive) 
$DiskInfo|ft

In our instance, Windows has detected three disks:

  • PHYSICALDRIVE0: SCSI Port zero, SCSI Target zero, Serial 6000c2939b157427dadbace321ed4973
  • PHYSICALDRIVE1: SCSI Port zero, SCSI Target 1, Serial 6000c2950ee961954909938642bb03b4
  • PHYSICALDRIVE1: SCSI Port four, SCSI Target 10, Serial 6000c2995fc3c4928d6650596bb02cef

get SCSI Controller and Device Number using Windows Powershell

Then let’s attempt to get SCSI controller numbers and UUIDs of the disks specified within the settings of the VMWare digital 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 
$digitalDiskSupervisor = Get-View -Id VirtualDiskSupervisor-virtualDiskSupervisor 

$vmresults = @()  
foreach ($vmHardDisk in $vmHardDisks)  
 Select-Object vmHardDiskDatastore,vmHardDiskVmdk,vmHardDiskName,vmHardDiskMeasurement,vmHardDiskUuid
  $vmresult.vmHardDiskDatastore = $vmHardDisk.filename.break up(']')[0].break up('[')[1]  
  $vmresult.vmHardDiskVmdk = $vmHardDisk.filename.break up(']')[1].trim()  
  $vmresult.vmHardDiskName = $vmHardDisk.Name
  $vmresult.vmHardDiskMeasurement = $vmHardDisk.CapacityGB
  $vmresult.vmHardDiskUuid = $vmHardDiskUuid    
  $vmresults += $vmresult  

$vmresults | ft 

This script will join to the vCenter (or ESXi) server and get the checklist of disks for the required VM.  The consequence should include the DataStore title, VMDK file path, disk quantity, disk measurement and UUID.

vmware powercli - get vmdk uuid

Then you possibly can manually match the disks you see within the visitor Windows OS with VMWare digital disks by their UUIDs.

If you could have administrator permissions within the visitor OS of the VM, you possibly can match Windows disks and VMWare VMDK information utilizing a extra handy PowerShell script. The script connects the visitor Windows OS over the community, collects the details about its native disks and matches them with VMWare VMDKs.

Here is the total code of the PowerShell script:

Import-Module VMware.VimAutomation.Core -ErrorAction SilentlyContinue
connect-viserver ber-vmware1
$vmName = "ber-man01"
$WinHostName = "ber-mansrv01.woshub.com"
#Get the checklist of disks of a VMWare digital machine
$vmDisks = Get-VM -Name $vmName | Get-HardDisk 
$vmDatacenterView = Get-VM -Name $vmName | Get-Datacenter | Get-View 
$digitalDiskSupervisor = Get-View -Id VirtualDiskSupervisor-virtualDiskSupervisor 
# Enter the administrator credentials to entry the visitor Windows
$cred = if ($cred)else  
# Getting the checklist of Windows disks and partitions utilizing WMI
$winDisk  = Get-WmiObject -Class Win32_DiskDrive -LaptopName $WinHostName -Credential $cred
$diskToDriveVolume = Get-WmiObject Win32_DiskDrive -LaptopName $WinHostName -Credential $cred| % {
  $disk = $_
  $partitions = "ASSOCIATORS OF " +
                " " +
                "WHERE AssocClass = Win32_DiskDriveToDiskPartition"
  Get-WmiObject -Query $partitions -LaptopName $WinHostName -Credential $cred| %  % 
  
}
 #Getting a disk serial quantity 
foreach ($disk in $winDisk)  
{  
  $disk | Add-Member -MemberType ObserveProperty -Name AltSerialNumber -Value $null 
  $diskSerialNumber = $disk.SerialNumber  
  if ($disk.Model -notmatch 'VMware Virtual disk SCSI Disk Device')  
    
}  
#Searching all VM disks and matching them with Windows disks by their SerialNumber / UUID
$diskMaps = @()  
foreach ($vmDisk in $vmDisks)  
 the place 
  $curDiskMap.drives = $driveVolumes.DriveLetter
  $curDiskMap.volumes = $driveVolumes.QuantityName
  $diskMaps += $curDiskMap
  
$diskMaps = $diskMaps | kind   
$diskMaps | ft

The script additionally returns details about drive letters and quantity labels in Windows.

powershell script to map Mapping guest VM drives to corresponding vmware VMDK files

Now you possibly can simply discover what Windows disk matches the given digital vmdk disk.

If digital disks in Windows are related through mount factors, there will probably be no details about the assigned drive letters and quantity labels within the output.

Check Also

How to Restore Deleted EFI System Partition in Windows 10?

In this text we’ll present you ways to manually restore an by chance deleted Windows …

Leave a Reply

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