Function Get-WindowsUpdates {
<#
.SYNOPSIS
Gather all windows updates installed.
.DESCRIPTION
This function will get all currently installed updates on the local server.
The particularity of this function is that it returns an Object which can be used in order to specefic filtering.
.EXAMPLE
$updates = Get-WindowsUpdates
$updates | select hotfixid
This will return all the current installed hotfixes
.NOTES
-Author: Stephane van Gulick
-Email :
-CreationDate:
-LastModifiedDate: 11/03/2014
-Version: 1.0
-History:
11/03/2014 --> Creation --> 0.5.1
.LINK
http://www.powerShellDistrict.com
https://social.technet.microsoft.com/profile/st%C3%A9phane%20vg/
#>
[fusion_builder_container hundred_percent="yes" overflow="visible"][fusion_builder_row][fusion_builder_column type="1_1" background_position="left top" background_color="" border_size="" border_color="" border_style="solid" spacing="yes" background_image="" background_repeat="no-repeat" padding="" margin_top="0px" margin_bottom="0px" class="" id="" animation_type="" animation_speed="0.3" animation_direction="left" hide_on_mobile="no" center_content="no" min_height="none"][cmdletBinding()]
Param(
)
Begin {
}
Process{
write-verbose "Start"
$Psupdates = @()
$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = $Session.CreateUpdateSearcher()
$HistoryCount = $Searcher.GetTotalHistoryCount()
if (!($HistoryCount)){
write-warning -Message "No updates found. Quiting."
break
}
$AllUpdates = $Searcher.QueryHistory(0,$HistoryCount)
$i = 0
While ($i -ne $HistoryCount){
$Update = @()
$psOperation = $Allupdates.Item($i).Operation
$PsResultCode = $Allupdates.Item($i).ResultCode
$PsHResult = $Allupdates.Item($i).HResult
$PSDate = $Allupdates.Item($i).Date
$PsUpdateIdentity = $Allupdates.Item($i).UpdateIdentity
$PsTitle = $Allupdates.Item($i).Title
$PsDescription = $Allupdates.Item($i).Description
$PsUnmappedResultCode = $Allupdates.Item($i).UnmappedResultCode
$PsClientApplicationID = $Allupdates.Item($i).ClientApplicationID
$PsServerSelection = $Allupdates.Item($i).ServerSelection
$PsServiceID = $Allupdates.Item($i).ServiceID
$PsUninstallationSteps = $Allupdates.Item($i).UninstallationSteps
$PsUninstallationNotes = $Allupdates.Item($i).UninstallationNotes
$PsSupportUrl = $Allupdates.Item($i).SupportUrl
$PsCategories = $Allupdates.Item($i).Categories
$PsDate = $Allupdates.Item($i).date
$HotFixID = $PsTitle | Select-String -Pattern 'KBd*' -AllMatches | % { $_.Matches } | % {$_.value}
$Properties = [Ordered]@{"HotFixID"=$HotFixID;
“Operation”=$psOperation;
"ResultCode" = $PsResultCode;
“HResult” = $PsHResult;
"Date" = $PSDate;
“UpdateIdentity” = $PsUpdateIdentity;
"Title" = $PsTitle;
“Description” = $PsDescription ;
"UnmappedResultCode" = $PsUnmappedResultCode;
“ClientApplicationID” = $PsClientApplicationID;
"ServerSelection" = $PsServerSelection;
“ServiceID” = $PsServiceID ;
“UninstallationSteps” = $PsUninstallationSteps;
"UninstallationNotes" = $PsUninstallationNotes;
“SupportUrl” = $PsSupportUrl;
"Categories" = $PsCategories;
}
$Update = New-Object -TypeName PSObject -Property $Properties
$PSUpdates += $Update
$i++
}
}#EndProcess
End{
Return $Psupdates
}
}
Leave A Comment