locked
Hot Fix If exists RRS feed

  • Question

  • I'm working on a script that will pull the hotfixes installed on a server. The hotfixes i'm looking for is in a text file. 

    I use get-content to load the hotfix KB numbers into an array. 

    What i want to do is run through the array and test for the hotfix information if one of the hot fixes in the list is not on the server, I want it to show me that.

    I was thinking of using if exist, but not sure how to make this work. Any ideas?


    Paul Arbogast

    Wednesday, June 11, 2014 5:59 PM

Answers

  • Hi Paul,

    This should give you a starting point:

    $computerName = 'COMPUTERNAME'
    
    $KBsToCheckFor = Get-Content .\KBsToCheckFor.txt
    
    $hotfixList = Get-HotFix -ComputerName $computerName
    
    $out = @()
    
    foreach ($kb in $KBsToCheckFor) {
    
        $props = @{
            ComputerName = $computerName
            KB = $kb
            Status = ''
        }
    
        If ($hotfixList.HotFixID -contains $kb) {
    
            $props.Status = 'Installed'
    
        } Else {
    
            $props.Status = 'NOT Installed'
    
        }
    
        $out += New-Object PsObject -Property $props
    
    }
    
    $out | Select ComputerName,KB,Status | Sort KB | Export-Csv ".\$computerName-KBStatus.csv" -NoTypeInformation



    Don't retire TechNet! - (Don't give up yet - 12,950+ strong and growing)

    • Marked as answer by parbogast Wednesday, June 11, 2014 6:39 PM
    Wednesday, June 11, 2014 6:17 PM

All replies

  • Hi Paul,

    This should give you a starting point:

    $computerName = 'COMPUTERNAME'
    
    $KBsToCheckFor = Get-Content .\KBsToCheckFor.txt
    
    $hotfixList = Get-HotFix -ComputerName $computerName
    
    $out = @()
    
    foreach ($kb in $KBsToCheckFor) {
    
        $props = @{
            ComputerName = $computerName
            KB = $kb
            Status = ''
        }
    
        If ($hotfixList.HotFixID -contains $kb) {
    
            $props.Status = 'Installed'
    
        } Else {
    
            $props.Status = 'NOT Installed'
    
        }
    
        $out += New-Object PsObject -Property $props
    
    }
    
    $out | Select ComputerName,KB,Status | Sort KB | Export-Csv ".\$computerName-KBStatus.csv" -NoTypeInformation



    Don't retire TechNet! - (Don't give up yet - 12,950+ strong and growing)

    • Marked as answer by parbogast Wednesday, June 11, 2014 6:39 PM
    Wednesday, June 11, 2014 6:17 PM
  • Man what you gave me there is great, thank you. Thats what I was looking for.


    Paul Arbogast

    Wednesday, June 11, 2014 6:38 PM
  • Wednesday, June 11, 2014 6:42 PM