Get Virtual Machine Bios Serial Number

I am using a PowerCLI script to clone virtual machines from a template and after the clone I need to add the new virtual machines to Altiris for further processing (deploying OS, Citrix XenApp and Applications in my case).
In Altiris I have universal jobs that identify what configuration is applicable, eg a Virtual Machine doesn’t need array configuration but a physical machine does.
I filter the Virtual Machines by using the Serial Number field in Altiris (a VMWare Virtual Machine always starts with the “VMware-“ followed by the VM’s UUID:

image

But I wanted to deploy the OS right after the clone operation and at this point Altiris has not yet read the serial number so I need to preconfigure this as well.

I wrote a PowerShell function that reads the UUID from a Virtual Machine and converts this to the desired format:

function Get-VMSerial
{
	param([VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl]$VirtualMachine)

	$s = ($VirtualMachine.ExtensionData.Config.Uuid).Replace("-", "")
	$Uuid = "VMware-"
	for ($i = 0; $i -lt $s.Length; $i += 2)
	{
		$Uuid += ("{0:x2}" -f [byte]("0x" + $s.Substring($i, 2)))
		if ($Uuid.Length -eq 30) { $Uuid += "-" } else { $Uuid += " " }
	}

	Write-Output $Uuid.TrimEnd()
}

A typical usage would be:

$VM = Get-VM MyVirtualMachine
Get-VMSerial -VirtualMachine $VM

Remko Weijnen

Was once an enthusiastic PepperByte employee but is now working elsewhere. His blogs are still valuable to us and we hope to you too.