PoshCode Archive  Artifact Content

Artifact 1088c8709294aa4a3a283b969171c94efd43324717a34bd5f696a437cdd562c9:

  • File Search-Windows-Updates.ps1 — part of check-in [2ae558fca4] at 2018-06-10 13:41:40 on branch trunk — ############################################################################################# (user: Rob Sewell size: 2249)

# encoding: utf-8
# api: powershell
# title: Search Windows Updates
# description: #############################################################################################
# version: 0.1
# type: function
# author: Rob Sewell
# license: CC0
# function: Search-WindowsUpdatesLocal
# x-poshcode-id: 4482
# x-archived: 2013-09-29T23:54:44
# x-published: 2013-09-22T10:47:00
#
# #
# NAME: Search-WindowsUpdatesLocal.ps1
# AUTHOR: Rob Sewell http://sqldbawithabeard.com
# DATE:22/09/2013
# #
# COMMENTS: Load function to show search for windows updates by KB locally
# #
# USAGE: Search-WindowsUpdatesLocal KB2792100|Format-Table -AutoSize -Wrap
#
#############################################################################################
#
# NAME: Search-WindowsUpdatesLocal.ps1
# AUTHOR: Rob Sewell http://sqldbawithabeard.com
# DATE:22/09/2013
#
# COMMENTS: Load function to show search for windows updates by KB locally
#
# USAGE: Search-WindowsUpdatesLocal KB2792100|Format-Table -AutoSize -Wrap
#    

Function Search-WindowsUpdatesLocal ([String] $Search)
{
$Search = $Search + "\d*" 
$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
    $SearchAnswer = $string | Select-String -Pattern $Search | Select-Object { $_.Matches } 
     $output = New-Object -TypeName PSobject
     $output | add-member NoteProperty “Date” -value $Update.Date
     $output | add-member NoteProperty “HotFixID” -value $SearchAnswer.‘ $_.Matches ‘.Value
     $output | Add-Member NoteProperty "Result" -Value $Result
     if($output.HotFixID)
     {
     $OutputCollection += $output
     }
 
    }

    $OutputCollection
    }