PoshCode Archive  Artifact Content

Artifact a2b89a4331a5c62850b582d77680abb4d034aa4ff0ebf5948bc3541a7b31f968:

  • File Show-WindowsUpdates.ps1 — part of check-in [d57f052d52] at 2018-06-10 13:41:43 on branch trunk — ############################################################################################# (user: Rob Sewell size: 2987)

# encoding: utf-8
# api: powershell
# title: Show-WindowsUpdates
# description: #############################################################################################
# version: 0.1
# type: function
# author: Rob Sewell
# license: CC0
# function: Show-WindowsUpdatesLocal
# x-poshcode-id: 4484
# x-archived: 2016-05-30T19:39:40
# x-published: 2016-09-23T22:22:00
#
# #
# NAME: Show-WindowsUpdatesLocal.ps1
# AUTHOR: Rob Sewell http://sqldbawithabeard.com
# DATE:22/09/2013
# #
# COMMENTS: Load function to show all windows updates locally
# #
# USAGE:  Show-WindowsUpdatesLocal
# Show-WindowsUpdatesLocal| Select Date, HotfixID, Result|Format-Table -AutoSize
# Show-WindowsUpdatesLocal|Where-Object {$_.Result -eq ‘Failed’} |Select Date, HotfixID, Result,Title|Format-Table -AutoSize
# Show-WindowsUpdatesLocal|Format-Table -AutoSize|Out-File c:\temp\updates.txt
# Show-WindowsUpdatesLocal|Export-Csv c:\temp\updates.csv
#
#############################################################################################
#
# NAME: Show-WindowsUpdatesLocal.ps1
# AUTHOR: Rob Sewell http://sqldbawithabeard.com
# DATE:22/09/2013
#
# COMMENTS: Load function to show all windows updates locally
#
# USAGE:  Show-WindowsUpdatesLocal
#         Show-WindowsUpdatesLocal| Select Date, HotfixID, Result|Format-Table -AutoSize
#         Show-WindowsUpdatesLocal|Where-Object {$_.Result -eq 'Failed'} |Select Date, HotfixID, Result,Title|Format-Table -AutoSize
#         Show-WindowsUpdatesLocal|Format-Table -AutoSize|Out-File c:\temp\updates.txt
#         Show-WindowsUpdatesLocal|Export-Csv c:\temp\updates.csv
#        

Function Show-WindowsUpdatesLocal
{
    $Searcher = New-Object -ComObject Microsoft.Update.Searcher
    $History = $Searcher.GetTotalHistoryCount()
    $Updates =  $Searcher.QueryHistory(1,$History)

    # Define a new array to gather output
    $OutputCollection=  @()
    
    Foreach ($update in $Updates)
        {
        $Result = $null
        Switch ($update.ResultCode)
            {
            0 { $Result = 'NotStarted'}
            1 { $Result = 'InProgress' }
            2 { $Result = 'Succeeded' }
            3 { $Result = 'SucceededWithErrors' }
            4 { $Result = 'Failed' }
            5 { $Result = 'Aborted' }
            default { $Result = $_ }
            }
    $string = $update.title
    $Regex = KB\d*
    $KB = $string | Select-String -Pattern $regex | Select-Object { $_.Matches }
    $output = New-Object -TypeName PSobject
    $output | add-member NoteProperty Date -value $Update.Date
    $output | add-member NoteProperty HotFixID -value $KB. $_.Matches .Value
    $output | Add-Member NoteProperty "Result" -Value $Result
    $output | add-member NoteProperty Title -value $string
    $output | add-member NoteProperty Description -value $update.Description

     $OutputCollection += $output
 
    }

    $OutputCollection
    }