I've been searching all over for a way I could match disks inside windows to vmware's harddisk
The problem is when I have disks with same scsi id on more than one scsicontroller (for ex. (1:0) and (0:0))
I found some scripts that compare the scsicontroller.bus number with the windows scsiport -1 but its not always the case..sometimes its -2 and sometimes its equal with no change. Any ideas? thanks in advance
I’m still waiting for a reaction.
I have found a way for this and it worked for me so far.
Go to Disk Management > Disk X > Properties > General > Location
Here, Location 160 is SCSI Controller 0 and Target ID is the location inside the controller.
This means SCSI(0:0) is Location 160 (Target ID 0)
SCSI(0:1) is Location 160 (Target ID 0)
SCSI(0:15) is Location 160 (Target ID 15)
SCSI(1:5) is Location 192 (Target ID 5) and so on
I came across the same question as everyone reading this post and I found FMON script the most useful for my purpose: query vm hard disks using a windows drive letter. I reused his code to write a PS module that integrates with existing VMWare cmdlets to ease resizing VM disks.
I have attached the module. You can simply extract it to C:\Windows\System32\WindowsPowerShell\v1.0\Modules or any other path in $env:PSModulePath. It exports a cmdlet called Get-VMHardDiskFromDriveLetter
After installing the module you can use it just like this:
Get-VM <vmname> | Get-VMHardDiskFromDriveLetter -DriveLetter D
The output will be the VM hard disk where this 😧 logical disk exists.
Because the cmdlet needs to access the guest OS, you must provide -Credential parameter that you can feed with a PS Credential if the currently logged in user doesn't have admin access to the Guest OS.
Get-VM <vmname> | Get-VMHardDiskFromDriveLetter -DriveLetter D -Credential (Get-Credential)
Then you can use the result and pipe it to the Set-HardDisk cmdlet to resize the disk where the partition exists.
Get-VM <vmname> | Get-VMHardDiskFromDriveLetter -DriveLetter D -Credential (Get-Credential) | Set-HardDisk -SizeGB 10
Thanks FMON.
Yes, until today 2018, there is no other way to consistently shows the result correctly.
How does one use this DiskPart script? Where does the output go?
saved my bacon on this one. i know im late to this party but ty
This is an old thread but I still couldn't find a good solution. But Powershell is more powerful now so I have come up with this.
###########
#Get-DiskFromLetter.ps1
# 2023-7-12 Wayne Boaz
# Script to determine vmware drive ID from Windows drive letter
###########
$viserver = read-host "Enter vcenter server where the host is located."
$computer = read-host "Enter Server Name."
$DriveLetter = read-host "Enter Drive Letter without the colon (i.e. F)."
Connect-VIServer $viserver
$diskid = get-partition -CimSession $computer -DriveLetter $DriveLetter | select -ExpandProperty diskid
$SerialNumber = get-disk -CimSession $computer | Where-Object {$_.path -eq "$diskid"} | select -ExpandProperty SerialNumber
get-vm $computer | Get-HardDisk | Where-Object {$_.ScsiCanonicalName -like "*$SerialNumber"} | select -Property Name, ScsiCanonicalName | ft -AutoSize
Disconnect-VIServer -server $viserver -confirm:$false
To take this thread to another level, if you have 4 scsi controllers and 4 disks on each controller on a vm. lets say you are there is a vmdk that is currently identified in windows as disk 4 and vmdk on scsi controller 1:0:0. for whatever reason, our end user states that no matter what windows disk 4 should always lineup with scsi controller 1:0:0. So now its patch Tuesday and the vm restarts. upon restarting this vm, the drive letters and windows disk are in a completely different order after said restart than before the restart, particularly scsi controller 1:0:0 now shows as windows disk 8, with a different underlying windows disk controller(ie, 160 vs 254)
how does one ensure that disk1:0:0 is always(after a restart) windows disk 4 and stay on the same underlying windows disk information?
Hi,
Thanks for the initial script it works great. I updated it to use PS v7 and WinRM. Help this helps someone.