none
Find installed hotfix & OS version RRS feed

  • Question

  • Hey Scripting Guy!

    I read your script here http://blogs.technet.com/b/heyscriptingguy/archive/2013/11/15/powertip-use-powershell-to-find-installed-hotfixes.aspx but it's too simple.


    I have this kind of requirement, quite simple:

    1. Check the specific Hotfix whether it's installed or not (e.g KB2479943 & KB2491683)
    2. Find what's the OS version

    What I have in hands:

    3. A list of servers in a csv file, named serverlist.csv


    I can't find a PS script anywhere that can meet this requirement and write the output to a txt/csv file. Please let me know if there's any?


    Thanks for your great help!


    ---Pat

    Friday, November 28, 2014 3:46 AM

Answers

  • This should work, it doesn't check whether the machines are online but it will get you the information you want.

    $KB = read-host "Enter a hotfixID"
    $res = @()
    import-csv C:\serverlist.csv | % {
    $server = $_.Server
    $os = (get-adcomputer -filter "Name -eq '$server'" -Properties OperatingSystem  | Select OperatingSystem).OperatingSystem
    
    if (get-hotfix -ComputerName $Server | ? {$_.HotfixID -eq $KB}) {
    
    
    $res += "" | Select -Property @{N="Server"; E={$Server}},
                                  @{N="OS"; E={$os}},
                                  @{N="Installed"; E={$true}} 
    
            }
    else {
    
    
    $res += "" | Select -Property @{N="Server"; E={$Server}},
                                  @{N="OS"; E={$os}},
                                  @{N="Installed"; E={$false}}
    
    
        }
    
    }
    $res | Export-csv C:\results.csv -NoTypeInformation

    • Marked as answer by Patrick M Sunday, November 30, 2014 12:23 AM
    Friday, November 28, 2014 10:31 AM
  • Here is a simplified version.

    $KB = read-host "Enter a hotfixID"
    import-csv C:\serverlist.csv | 
        ForEach-Object{
            $p=@{
                Server=$_.server
                OS=$null
                Installed=$false
    	    }
            $p.OS=(get-adcomputer $_.server -Properties OperatingSystem).OperatingSystem
            $p.Installed=(get-hotfix $KB -ComputerName $_.server) -ne $null
            New-Object PsObject -Property $p
        } | 
        Export-csv C:\results.csv -NoTypeInformation


    ¯\_(ツ)_/¯



    • Edited by jrv Saturday, November 29, 2014 9:45 AM
    • Marked as answer by Patrick M Sunday, November 30, 2014 12:24 AM
    Saturday, November 29, 2014 9:35 AM
  • Hi Patrick, it should work fine, i tested it before posting. How is your csv formatted, what are th column headers+
    • Marked as answer by Patrick M Sunday, November 30, 2014 12:24 AM
    Saturday, November 29, 2014 8:42 AM
  • How is your csv structured? What column titles/headers do you use? The script assumes it is servers so it will need changing to match whatever your header is.
    • Marked as answer by Patrick M Sunday, November 30, 2014 12:24 AM
    Saturday, November 29, 2014 12:07 PM

All replies

  • I think you will have to learn to write a script.

    Start here: http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx


    ¯\_(ツ)_/¯

    Friday, November 28, 2014 4:27 AM
  • This should work, it doesn't check whether the machines are online but it will get you the information you want.

    $KB = read-host "Enter a hotfixID"
    $res = @()
    import-csv C:\serverlist.csv | % {
    $server = $_.Server
    $os = (get-adcomputer -filter "Name -eq '$server'" -Properties OperatingSystem  | Select OperatingSystem).OperatingSystem
    
    if (get-hotfix -ComputerName $Server | ? {$_.HotfixID -eq $KB}) {
    
    
    $res += "" | Select -Property @{N="Server"; E={$Server}},
                                  @{N="OS"; E={$os}},
                                  @{N="Installed"; E={$true}} 
    
            }
    else {
    
    
    $res += "" | Select -Property @{N="Server"; E={$Server}},
                                  @{N="OS"; E={$os}},
                                  @{N="Installed"; E={$false}}
    
    
        }
    
    }
    $res | Export-csv C:\results.csv -NoTypeInformation

    • Marked as answer by Patrick M Sunday, November 30, 2014 12:23 AM
    Friday, November 28, 2014 10:31 AM
  • @jrv

    thank you



    • Edited by Patrick M Saturday, November 29, 2014 11:53 AM
    Saturday, November 29, 2014 12:41 AM
  • Dear Braham20

    Yours was the most helpful :)

    I'm still figuring it's way on how I can get the desired result.

    As I ran your script, the result.csv will just be a blank file without any output written to it.

    I'm starting to learn PS, and still not talented in scripting. Some of the operators are just confusing me.

    I'll use your script as a good base for learning as I wanted to get the result I desired.


    Thank you so much for helping!

    Cheers! :)


    ---Pat

    Saturday, November 29, 2014 12:47 AM
  • Hi Patrick, it should work fine, i tested it before posting. How is your csv formatted, what are th column headers+
    • Marked as answer by Patrick M Sunday, November 30, 2014 12:24 AM
    Saturday, November 29, 2014 8:42 AM
  • Hi Patrick, it should work fine, i tested it before posting. How is your csv formatted, what are th column headers+

    #To show you that KB2868626 is installed on the computer:

    #---------------------------------------------------------------------------------------
    PS C:\TEMP> Get-HotFix
    
    Source        Description      HotFixID      InstalledBy          InstalledOn
    ------        -----------      --------      -----------          -----------
    ADS1          Update           KB2843630     SXC\Administrator    10/19/2014 12:00:00 AM
    ADS1          Security Update  KB2862152     NT AUTHORITY\SYSTEM  10/19/2014 12:00:00 AM
    ADS1          Security Update  KB2868626     SXC\Administrator    10/19/2014 12:00:00 AM
    #---------------------------------------------------------------------------------------
    PS C:\TEMP> get-hotfix -ComputerName ADS1 -Id KB2868626
    
    Source        Description      HotFixID      InstalledBy          InstalledOn
    ------        -----------      --------      -----------          -----------
    ADS1          Security Update  KB2868626     SXC\Administrator    10/19/2014 12:00:00 AM
    
    
    PS C:\TEMP>
    #---------------------------------------------------------------------------------------
    


    #But when I ran the script (after modifying the path to C:\TEMP this is what I got:

    PS C:\TEMP> .\getHotfix.ps1
    Enter a hotfixID: KB2868626
    PS C:\TEMP>
    
    PS C:\TEMP> dir
    
    
        Directory: C:\TEMP
    
    
    Mode                LastWriteTime     Length Name
    ----                -------------     ------ ----
    -a---        11/29/2014   5:13 PM        743 getHotfix.ps1
    -a---        11/29/2014   5:22 PM          0 results.csv
    -a---        11/29/2014   5:13 PM          4 serverlist.csv
    
    
    PS C:\TEMP>
    

    #As you can see the file results.csv has 0KB and has no content.

    #This is my PowerShell version if it helps

    PS C:\TEMP> Get-Host
    
    
    Name             : ConsoleHost
    Version          : 4.0
    InstanceId       : fc22c61a-3bba-4294-954d-69ce2751957d
    UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
    CurrentCulture   : en-US
    CurrentUICulture : en-US
    PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
    IsRunspacePushed : False
    Runspace         : System.Management.Automation.Runspaces.LocalRunspace
    
    
    
    PS C:\TEMP>
    

    #And ExecutionPolicy was set to Unrestricted

    PS C:\TEMP> Get-ExecutionPolicy
    Unrestricted
    PS C:\TEMP>


    ---Pat

    Saturday, November 29, 2014 9:26 AM
  • Here is a simplified version.

    $KB = read-host "Enter a hotfixID"
    import-csv C:\serverlist.csv | 
        ForEach-Object{
            $p=@{
                Server=$_.server
                OS=$null
                Installed=$false
    	    }
            $p.OS=(get-adcomputer $_.server -Properties OperatingSystem).OperatingSystem
            $p.Installed=(get-hotfix $KB -ComputerName $_.server) -ne $null
            New-Object PsObject -Property $p
        } | 
        Export-csv C:\results.csv -NoTypeInformation


    ¯\_(ツ)_/¯



    • Edited by jrv Saturday, November 29, 2014 9:45 AM
    • Marked as answer by Patrick M Sunday, November 30, 2014 12:24 AM
    Saturday, November 29, 2014 9:35 AM
  • thanks again, jrv

    I'm still getting null result from running the script

    Now I wonder how come you can get the results by running the same script but not me?

    My PS version is 4.0 and ExecutionPolicy = Unrestricted


    :(


    ---Pat

    Saturday, November 29, 2014 11:44 AM
  • How is your csv structured? What column titles/headers do you use? The script assumes it is servers so it will need changing to match whatever your header is.
    • Marked as answer by Patrick M Sunday, November 30, 2014 12:24 AM
    Saturday, November 29, 2014 12:07 PM
  • Found the issue was with header not structured properly. Fixed that and now I got it working.

    BIG Thanks, Braham20! :)


    ---Pat

    Sunday, November 30, 2014 12:23 AM