Powershell script to check whether multiple KB are installed or not in servers

This topic contains 2 replies, has 3 voices, and was last updated by  Jon 1 month, 2 weeks ago.

  • Author
    Posts
  • #87911

    Shalomon
    Participant

    Powershell Script to find patched and unpatched server!

    I have multiple KB's, I am trying to find whether those KB's have been patched in those servers.

    I have two text file, One contains servers list and other one contains KB list.

    Please find my script below.

    $computers = Get-Content -path "C:\Temp\Shalomon\MultipleKB\server_list.txt"
    $Patch = Get-Content -path "C:\Temp\Shalomon\MultipleKB\kb_list.txt"
    foreach ($computer in $computers)
    {
    if (get-hotfix -id $Patch -ComputerName $computer -ErrorAction SilentlyContinue)
    {
    Add-content "$Patch is Present in $computer" -path "C:\Temp\Shalomon\MultipleKB\Hotfix-Present.txt"
    }
    Else
    {
    Add-content "$Patch is not Present in $computer" -path "C:\Temp\Shalomon\MultipleKB\Missing-Hotfix.txt"
    }
    }

    **************But i get the output as

    KB4025337 KB4025252 is Present in vmpip-xxxx
    KB4025337 KB4025252 is Present in vmpip-yyyy
    KB4025337 KB4025252 is Present in VMPIP-zzzz

    Note: I do not get the servers in which the KB's are missing, Can someone help me out in this code!

  • #87919

    Jeremy Corbello
    Participant

    Here, use this one. Made it a while back to do exactly that.
    https://www.jeremycorbello.com/index.php/powershell/general-scripts/5-get-mshotfix-ps1

  • #87931

    Jon
    Participant

    Change this:

    get-hotfix -id $Patch -ComputerName $computer -ErrorAction SilentlyContinue

    To:

    get-hotfix -id $Patch -ComputerName $computer -ErrorAction SilentlyContinue -outvariable patchresult

    Then do if your if/else on the $patchresult variable, if the variable is not null then you know you have the patch, if it's null then you don't have it.

You must be logged in to reply to this topic.