New Script – Get VM or ESX Host UUIDs (get-uuid.ps1)

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


[VI Toolkit] C:\> get-vmhost | select -first 1 | .\scripts\get-uuid.ps1


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.

5 thoughts on “New Script – Get VM or ESX Host UUIDs (get-uuid.ps1)

Comments are closed.