Below is the function. It gets a Uuid for a virtual machine, which looks like this:
42125df4-e589-b449-2329-1c0b5e01cdc5
And parses it so that it ends up looking like this:
VMware-42 12 5d f4 e5 89 b4 49-23 29 1c 0b 5e 01 cd c5
The lines that are confusing to me are below. I want to understand what each part does. It works great. I just don’t know how.
$Uuid += ("{0:x2}" -f [byte]("0x" + $s.Substring($i, 2))) if ($Uuid.Length -eq 30) { $Uuid += "-" } else { $Uuid += "
Below is the entire function.
function Get-VMSerial { param([VMware.VimAutomation.ViCore.Impl.V1.VM.UniversalVirtualMachineImpl]$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() }
submitted by /u/Dracolis
[link] [comments]
The post [Question] Function formats a Uuid for me, but I don’t understand how it works appeared first on How to Code .NET.