In windows, a Get-Disk will produce a list of disks with serial numbers. In vMware, a (get-harddisk -vm $vmname).ExtensionData.Backing.Uuid will produce a list of vmdk UUIDs which match the serial numbers produced in windows.
I want to use this fact to correlate what disk in windows resides on what vmdk/vmware disk in vCenter. I would also like to correlate the windows volume name as well. However, i am struggling to get the logic to actually work.
There are a couple of conditions for this to work.
This works for Windows 10 and 2016, when
Disclaimer 1: I only tested this with Windows 10 and Server 2016
Disclaimer 2: this only works for disks. There is afaik no fool-proof method to map guest OS partitions to VMDK
$user = 'LucD'
$pswd = 'VMware1!'
$code = @'
Get-Disk | Select DiskNumber,SerialNumber | ConvertTo-Csv
'@
$vm = Get-VM -Name $vmName
if ($vm.Guest.State -ne 'Running')
{
if ((Get-AdvancedSetting -Entity $vm -Name 'disk.EnableUUID').Value -eq 'true')
{
$diskTab = @{ }
Invoke-VMScript -VM $vm -ScriptText $code -GuestUser $user -GuestPassword $pswd |
select -ExpandProperty ScriptOutput | ConvertFrom-Csv |
ForEach-Object -Process {
$diskTab.Add($_.SerialNumber, $_.DiskNumber)
}
Get-HardDisk -VM $vm |
Select @{N = 'VM'; E = { $_.Parent.Name } }, Name,
@{N = 'Uuid'; E = { $_.ExtensionData.Backing.Uuid } },
@{N = 'WinDisk'; E = { $diskTab[$_.ExtensionData.Backing.Uuid.Replace('-', '')] } }
}
else
{
Write-Host 'Serial number not showing (see KB52815)'
}
}
else
{
Write-Host "VMware Tools need to be installed and running"
}
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
There are a couple of conditions for this to work.
This works for Windows 10 and 2016, when
Disclaimer 1: I only tested this with Windows 10 and Server 2016
Disclaimer 2: this only works for disks. There is afaik no fool-proof method to map guest OS partitions to VMDK
$user = 'LucD'
$pswd = 'VMware1!'
$code = @'
Get-Disk | Select DiskNumber,SerialNumber | ConvertTo-Csv
'@
$vm = Get-VM -Name $vmName
if ($vm.Guest.State -ne 'Running')
{
if ((Get-AdvancedSetting -Entity $vm -Name 'disk.EnableUUID').Value -eq 'true')
{
$diskTab = @{ }
Invoke-VMScript -VM $vm -ScriptText $code -GuestUser $user -GuestPassword $pswd |
select -ExpandProperty ScriptOutput | ConvertFrom-Csv |
ForEach-Object -Process {
$diskTab.Add($_.SerialNumber, $_.DiskNumber)
}
Get-HardDisk -VM $vm |
Select @{N = 'VM'; E = { $_.Parent.Name } }, Name,
@{N = 'Uuid'; E = { $_.ExtensionData.Backing.Uuid } },
@{N = 'WinDisk'; E = { $diskTab[$_.ExtensionData.Backing.Uuid.Replace('-', '')] } }
}
else
{
Write-Host 'Serial number not showing (see KB52815)'
}
}
else
{
Write-Host "VMware Tools need to be installed and running"
}
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This is similar to what I was working on only much better. I to am thinking that a volume mapping just cannot be done. I cannot seem to find any kind of unique identifier to tie it into. Thanks LucD, as always, you were shockingly helpful!