Verifying installed updates

In many cases, you will also need to check for specific updates on the machines. The following code retrieves the information for the installed updates. You can also specify dedicated computers to verify installed updates remotely:

 <#    
.SYNOPSIS
Get-InstalledUpdateInformation retrieves a list of Windows and Microsoft Updates for the specified computer.

.DESCRIPTION
Get-InstalledUpdateInformation retrieves a list of Windows and Microsoft Updates for the specified computer. Requires admin rights.

.PARAMETER ComputerName
A specified computername, if you want to retrieve the information from a different computer.

.EXAMPLE
Get-InstalledUpdateInformation
.EXAMPLE
Get-Content ServerList.Csv | Select-Object ComputerName | Get-InstalledUpdateInformation

.NOTES
Get-InstalledUpdateInformation retrieves a list of Windows and Microsoft Updates for the specified computer.
#>

Function
Get-InstalledUpdateInformation
{
[CmdletBinding()]
Param (
[Parameter(position = 0,Mandatory = $False,ValueFromPipeline =
$true,ValueFromPipelinebyPropertyName = $true)][Alias('Name')]
$ComputerName = $env:computername
)
Begin
{
function Test-ElevatedShell
{
$user = [Security.Principal.WindowsIdentity]::GetCurrent()
(New-Object -TypeName Security.Principal.WindowsPrincipal -ArgumentList $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
$admin = Test-ElevatedShell
}
PROCESS
{
If($admin)
{
$null = [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.Update.Session')
$Session = [activator]::CreateInstance([type]::GetTypeFromProgID('Microsoft.Update.Session',$ComputerName))
$Searcher = $Session.CreateUpdateSearcher()
$historyCount = $Searcher.GetTotalHistoryCount()
$Searcher.QueryHistory(0, $historyCount) | Select-Object -Property Date, @{ name = 'Operation' expression = {
switch($_.operation){1 {'Installation'};2 {'Uninstallation'};3 {'Other'}}}},@{ name = 'Status' expression = {switch($_.resultcode){1 {'In Progress'};2 {'Succeeded'};3 {'Succeeded With Errors'};4 'Failed'};5 {'Aborted'}}}}, Title, @{ name = 'PC' expression = { $ComputerName } } }
else
{
         'Administrative rights are necessary.'
}
}
}

Sometimes, it is also important to check specific KBs, such as the antivirus definitions. This is very often the case if a current threat is found and you need the current definitions to enable the antivirus to find them:

#Retrieving all Update information
$Updates = Get-InstalledUpdateInformation

#Defender Updates -- KB2267602
$Updates.Where{ $_.Title -like '*KB2267602*' } | Sort-Object -Descending Date | Out-GridView

With the last line, you will retrieve a good sorted list. When taking a look at this list, keep an eye on the Status and the Definition version at the end of the title. For privacy reasons, I have hidden the computer name:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.6.194