Skip to content

Get-HostPatch

VMware: Retrieves the host patches installed on the specified host

#Requires -Version 5.1
#Requires -Modules VMware.VimAutomation.Core
[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)]
    [string]$VIServer,
    [Parameter(Mandatory = $true)]
    [pscredential]$VICredential,
    [Parameter(Mandatory = $true)]
    [string]$HostName,
    [ValidateSet('*', 'Name', 'InstallDate', 'AcceptanceLevel', 'CreationDate', 'ID', 'Status', 'Vendor', 'Version')]
    [string[]]$Properties = @('Name', 'InstallDate', 'AcceptanceLevel', 'CreationDate', 'ID', 'Status', 'Vendor', 'Version')
)
Process {
    $vmServer = $null
    try {
        if ($Properties -contains '*') { $Properties = @('*') }
        $vmServer = Connect-VIServer -Server $VIServer -Credential $VICredential -ErrorAction Stop
        $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
        $vmHost = Get-VMHost -Server $vmServer -Name $HostName -ErrorAction Stop
        $result = (Get-ESXCli -VMHost $vmHost).software.vib.list() | Select-Object $Properties
        foreach ($item in $result) {
            $item | Add-Member -NotePropertyName 'Timestamp' -NotePropertyValue $timestamp -Force
            Write-Output $item
        }
    }
    catch { throw }
    finally { if ($null -ne $vmServer) { Disconnect-VIServer -Server $vmServer -Force -Confirm:$false -ErrorAction SilentlyContinue } }
}

IP address or DNS name of the vSphere server

PSCredential object for authenticating with the server

Name of the host to retrieve patches from

List of properties to expand; use * for all properties

An interactive directory of PowerShell scripts.