Few of the articles are posted as Images, Please use Laptop / Computers to go through the articles for best experience. For phone users, switch to Web Version

Please Share with your colleagues if you found these blogs informative. Happy Learning :-)

Powershell Script - KB Installation Status on Windows Servers / Clients.

 #Created By - Abhishek Bansal
<#Read Me !! 
1. Script will check if a KB mention in Input.csv against a Server name is installed or not.
2. Input.csv file header heading should not be changed. If planning to change, then changes are required in script also.
3. Once executed, Output.csv can be referred for the results.
To use this, copy the below code, have Input.csv on the same location with MachineName,KBID heading.
KBID - will be containing KBNo.
Machine Name -Server name against check is required.
#>

$checkdata = Import-Csv .\Input.csv
$line = 0 
$linecount = $checkdata.count
$percentagecomplete= 0 
    foreach($srv in $checkdata)
    {
    $percentagecomplete = ($line / $linecount) * 100
       $KB = $srv.KBID
       $error.Clear()
       Write-Progress -Activity "Checking Status.." -PercentComplete $percentagecomplete -Status "$line out of $linecount"
        try{
            if(($output = Get-HotFix -ComputerName $srv.'MachineName' -Id $KB).HotfixID -eq $KB) 
            {
            $srv |  Select @{n="MachineName";e={$srv.MachineName}},@{n="HotFixID";e={$KB}},@{n="InstalledOn";e={$output.InstalledOn}}  | Export-Csv ./Output.csv -Append -NoTypeInformation
            }
            
            else
            {
           $srv |  Select @{n="MachineName";e={$srv.MachineName}},@{n="HotFixID";e={$KB}},@{n="InstalledOn";e={"Not Installed"}} | Export-Csv ./Output.csv -Append -NoTypeInformation
            }
            }
            catch 
            {
           
            $srv | Select @{n="MachineName";e={$srv.MachineName}},@{n="HotFixID";e={$KB}},@{n="InstalledOn";e={$error.exception.Message}}  | Export-Csv ./Output.csv -Append -NoTypeInformation
             
            }
            $line++
    }
  

No comments:

Post a Comment