Have you ever found yourself wondering when a certain ESXi server was installed? In this case VMware GSS has your back. Check out KB 2144905 to find a simple esxcli command that dissects the hosts UUID to give you the installation date of that specific host. But what if you want to audit an entire cluster? This is where Powershell can help you out.

The KB article describes how the date is derived from the first part of the UUID. This is a hex representation of a UNIX timestamp. When converted to an integer you can use this to calculate the installation date. Because yes, most of us cannot interpret a UNIX timestamp like Neo can. 😁

That is why us mere mortals can use the power of Powershell to create an overview. I created this function to replicate the one-liner from VMware. Have fun using it if you ever need to query the install date on your ESXi hosts.

function Get-VMHostInstallDate {
    Param(
        [parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl]
        $VMHost,

        [parameter(Mandatory = $false, ValueFromPipeline = $false)]
        [switch]
        $UTC
    )

    begin {}
    process {
        try {
            $esxcli = Get-EsxCli -VMHost $VMhost -V2
            Write-Verbose "$(Get-Date -Format G) Checking installation date on [$($VMhost)]"
            $result = $esxcli.system.uuid.get.Invoke()
            Write-Verbose "$(Get-Date -Format G) VMhost UUID: $($result)"
            # Selecting first part of the UUID and convert it from hex to unsigned integer
            $InstallDateUnix = [uint32]"0x$(($result).split("-")[0])"
            Write-Verbose "$(Get-Date -Format G) VMhost InstallDate Unix timestamp: $($InstallDateUnix)"
            # Creating datetime value from Unix time
            if ($UTC) {
                # If UTC parameter has been set then pass the datetime as-is
                $InstallDate = ((Get-Date 01.01.1970)+([System.TimeSpan]::fromseconds($InstallDateUnix)))
            }
            else {
                # If UTC parameter has been set then convert to local time
                $InstallDate = ((Get-Date 01.01.1970)+([System.TimeSpan]::fromseconds($InstallDateUnix))).ToLocalTime()
            }
        }
        catch {
            throw "Error occured while retreiving install date: $_"
        }

        # Produce output
        [PSCustomObject]@{
            VMHost = $vmHost
            InstallDate = $InstallDate
        }
    }
}

Rudolf Kleijwegt

I am an experienced IT professional with over 20 years of hands-on experience designing, deploying, and maintaining IT infrastructure in both enterprise and service provider environments. My skills span across Linux and Windows and a multitude of server applications, allowing me to excel in a wide range of IT roles. Currently, my primary focus is on Software Defined DataCenter and DevOps. I am passionate about staying up to date with the latest trends in the industry to achieve superior outcomes.

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *