Results 1 to 4 of 4
  1. #1
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts

    Powershell to list Installed Windows Updates in numerically sorted order.

    Hey Y'all,

    Don't know about you but I always have trouble comparing the Windows Secrets update list to that in Windows Update History since the Numbers in WUH are not in numerical order nor are they in a nice neat row. So I thought this would be a good problem to tackle as a project in my continuing oddessy to learn PowerShell.

    The program below will at least make it easier to scan your installed updates. You can even send the output to a .csv file for loading into Excel for further manipulation.
    Code:
    # +---------------------------------------------+
    # | Computer Mentors Windows Update List V1-6   |
    # +---------------------------------------------+
    
    param (
       [string]$ToPath,               #Will send output to file named in this path
       [string]$ToFile = "WinUpdList" #or this file if specified overwriting w/o prompt!.
    )                                 #filetype will always be .csv!
    <#  -------------------------------------------------
    Requires: Get-WUHistory.ps1 file avaliable at: 
              http://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc
              Note the .zip file contains several files you only need the Get-WUHistory.ps1 file.
              This file must be turned into a Module and loaded or incorporated into this script.
              Instructions on Converting/Loading Modules can be found at:
              http://stackoverflow.com/questions/6016436/in-powershell-how-do-i-define-a-function-in-a-file-and-call-it-from-the-powersh
              See the post that starts with "What you are talking about is called Dot Sourcing. And it's evil."
              Follow the directions as listed.
        -------------------------------------------------------------------     
        
        Calling Syntax:
        For screen display:    .\WindowsUpdatesortedListV1-6.ps1
        Send output to file:   .\WindowsUpdateSortedListV1-6.ps1 
                                    -ToPath "full-PATH-specification"
                                    -ToFile "filename" ONLY NO filetype!
        Note:                  Filename defaults to at WinUpdList
                               Filetype fixed at .csv
                               If no -ToPath output to Screen
      ----------------------------------------------------------------------
    #>
    
    $fmt = @{Expression={[int] $_.KB.substring(2,$_.KB.Length-2)};Label="KB Number";width=9},
                 @{Expression={'{0:MM/dd/yyyy}' -f $_.Date};Label="Date";width=10},
                 @{Expression={$_.ClientApplicationID};Label="Install Client";width=18},
                 @{Expression={$_.Title};Label="Title"}
    
    $ErrorActionPreference = "SilentlyContinue"
    
    $DirectoryExists = Get-Childitem( "$ToPath\*.*" )
    
    if($DirectoryExists -eq $null) {
       $ToPath=""
       Write-Host "File Path Invalid...Sending output to Screen."
    }
    
    Import-Module Get-WUHistory
    <#
           Filter Out Non-Windows, e.g. blank KB numbers and
           Microsoft Security Essentials Definition Updates KB2310138 and
           Windows Defender Definition Updates              KB2267602.
           Sorted in KB Number order (Ascending) then Date (Decending). 
           Note: numbers are not aligned since they are part of a string!.
    #>
         
           $TempOutput = Get-WUHistory  | Where-Object {@("","KB2310138","KB2267602","KB982726") -notcontains $_.KB} | `
                         Sort-Object -property @{Expression={[int] $_.KB.substring(2,$_.KB.Length-2)};Ascending=$true}, `
                                               @{Expression={$_.Date};Descending=$true}
     if($ToPath -eq "") {
                  $TempOutput|  Format-Table $fmt 
          }
          Else {
                  $TempOutput | `
                  Select-Object -property @{Expression={[int] $_.KB.substring(2,$_.KB.Length-2)}}, Date,ClientApplicationID,Title | `
                  Export-csv -Path "$ToPath\$ToFile.csv" -Force
                  Write-Host "Data written to $ToPath\$ToFile.csv"
          }
    Hope some of you find it useful.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  2. #2
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,188
    Thanks
    47
    Thanked 983 Times in 913 Posts
    Or use PSTools "psinfo -s".

    cheers, Paul

  3. #3
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Paul,

    Interesting tools, however I don't see how they provide the same information and/or functionality.
    I've attached output from both my program and the PSInfo command.
    Attached Files Attached Files
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  4. #4
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,188
    Thanks
    47
    Thanked 983 Times in 913 Posts
    I see you want a comprehensive list for use in a spreadsheet, which psinfo won't do - it only reports the program list shown in Add/Remove.

    cheers, Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •