UUIDs are wonderful! Really. They’re just not all that easy to get to, at least not when you need more than a few of them at a time. That is where this script comes in:
# get-uuid.ps1
#
# Takes either a VMHost or VM object from the pipeline, returns the corresponding UUID.
Begin {
$VMHost_UUID = @{
Name = "VMHost_UUID"
Expression = { $_.Summary.Hardware.Uuid }
}
$VM_UUID = @{
Name = "VM_UUID"
Expression = { $_.Config.Uuid }
}
}
Process {
$InputTypeName = $_.GetType().Name
if ( $InputTypeName -eq "VMHostImpl" ) {
$_ | Get-View | Select-Object $VMHost_UUID
} elseif ( $InputTypeName -eq "VirtualMachineImpl" ) {
$_ | get-view | Select-Object $VM_UUID
} else {
Write-Host "`nPlease pass this script either a VMHost or VM object on the pipeline.`n"
}
}
Excusing the line wrap and odd orange color, you can see in the “Begin” block, that we define the two properties, based on their location in the API. In the process block we do some error checking, and then grab the relevant UUIDs.
The output looks similar to:
[VI Toolkit] C:\> get-vm | select -first 1 | .\scripts\get-uuid.ps1
VM_UUID
——-
50205819-19c6-965d-8d70-dbad7c43e598
[VI Toolkit] C:\> get-vmhost | select -first 1 | .\scripts\get-uuid.ps1
VMHost_UUID
———–
44454c4c-4a00-104d-8042-cac04f544831
The script can be downloaded here. Please note, that it was discovered while researching this post that the VMHost UUIDs stored by vCenter 2.5 U3 may or may not actually be unique. I have an active SR around this, and will make a follow up post once we get it sorted.
How about if you just open the VI Client, select the Datacenter object on the left, click the VM tab on the right, right click on one of the grey column headers, and click to select the UUID column so it is visible for all VMs? You can even save the VM list as a .xls file from the File menu too. 😉
Good catch. I've grown so accustomed to poking at things from an automation
stand point. I didn't see however, where to get the host UUIDs from the VI
client, however, and the script does provide that.
Thanks!
How about if you just open the VI Client, select the Datacenter object on the left, click the VM tab on the right, right click on one of the grey column headers, and click to select the UUID column so it is visible for all VMs? You can even save the VM list as a .xls file from the File menu too. 😉
Good catch. I've grown so accustomed to poking at things from an automation
stand point. I didn't see however, where to get the host UUIDs from the VI
client, however, and the script does provide that.
Thanks!