Wednesday, March 25, 2015

Find Specific MS HF using Powershell


From time to time, especially in my country, we need to recursively search for a specific Hot Fix installed on the system.

In the script below we show how to search for the following KB, KB2863058
This can be change to fit your needs.

$list = Get-Content C:\tmp\list.txt
$Exception = ""
$Updates = ""
$OperatingSystem = ""
$Update_KB2863058 = ""

$BigResult = foreach ($l in $list) {

    Clear-Variable OperatingSystem
    Clear-Variable Updates
    Clear-Variable Exception
    Clear-Variable Update_KB2863058

    $result = "" |select -Property Name, OS, Update_KB2863058

    $OperatingSystem = Get-WmiObject -ComputerName $l -Class Win32_OperatingSystem
                        
    if ($OperatingSystem -ne $null) {

        $Updates = Get-WmiObject -ComputerName $l -Class Win32_QuickFixEngineering
        if ($Updates.count -gt "1") {
            $Update_KB2863058 = $Updates | ? {$_.HotFixID -eq "KB2863058"}
            
            if ($Update_KB2863058 -eq $null) {
                $result.Update_KB2863058 = "Not Installed"}
            else {$result.Update_KB2863058 = "Installed"}
        }
        else {
            $Update_KB2863058 = "Please Check Manually";
            $result.Update_KB2863058 = $Update_KB2863058;
        }

        $result.Name = $l
        $result.OS = $OperatingSystem.Caption

        $result

    } # END OperationSystem IF
                        
    else {
        $result.Name = $l; $result.Update_KB2863058 = "Can't Connect"; $result;
    }

} # END Foreach

$BigResult | Export-Csv -Path C:\tmp\GetInstalledHotFix.csv



Enjoy.

No comments:

Post a Comment