Public/Get-WindowsHotfixes.ps1

<#
.SYNOPSIS
    Retrieves a list of installed Windows updates (hotfixes) on the local machine.
 
.DESCRIPTION
    This function uses the Windows Management Instrumentation Command-line (WMIC) tool to list all the hotfixes
    installed on the local machine. It formats the output into a more readable PowerShell object list.
 
.OUTPUTS
    System.Management.Automation.PSCustomObject
    Returns custom objects with detailed information about each hotfix.
 
.EXAMPLE
    Get-WindowsHotfixes
    Retrieves hotfixes and displays detailed information in a formatted list.
    $params1 = @{
    ComputerName = "jmp001"
    ScriptBlock = ${function:Get-WindowsHotfixes}
    #filter= {$_.Installedon -gt ((Get-Date).Adddays(-2))}
    }
 
    Invoke-Command @params1|Where-Object {([DateTime]$_.Installedon) -gt ((Get-Date).Adddays(-30))}|Select-Object -Property Computername, KBArticle,InstalledOn, HotFixID, InstalledBy|Format-Table
    Retrieves hotfixes and displays detailed information in a formatted Table on remote computer.
     
.NOTES
    Requires administrative privileges on the remote computer and appropriate permissions to use PowerShell remoting.
#>

function Get-WindowsHotfixes {
    [CmdletBinding()]
    [OutputType([PSCustomObject])]
    $outputs = Invoke-Expression "wmic qfe list"
    $outputs = $outputs[1..($outputs.length - 1)]  # Skip the header line

    foreach ($output in $outputs) {
        if ($output) {
            # Replace certain strings for consistent splitting
            $output = $output -replace 'Security Update', 'Security-Update' -replace 'NT AUTHORITY', 'NT-AUTHORITY' -replace '\s+', ' '
            $parts = $output -split ' '
            
            # Date processing based on the expected format in part[5]
            $dateString = $parts[5]
            $dateis = if ($dateString -like "*/*/*") {
                [datetime]::ParseExact($dateString, 'M/d/yyyy', [Globalization.CultureInfo]::InvariantCulture)
            } else {
                (Get-Date ([DateTime][Convert]::ToInt64($dateString, 16))).ToString('M/d/yyyy')
            }

            # Construct the output object
            [PSCustomObject]@{
                KBArticle = $parts[0]
                Computername = $parts[1]
                Description = $parts[2]
                FixComments = $parts[6]
                HotFixID = $parts[3]
                InstalledOn = $dateis.ToString("dddd, d MMMM yyyy")
                InstalledBy = $parts[4]
                InstallDate = $parts[7]
                Name = $parts[8]
                ServicePackInEffect = $parts[9]
                Status = $parts[10]
            }
        }
    }
}