[Windows] Add test to validate windows updates installation (#4489)

* Add test to validate windows updates installation

* Add function Get-WindowsUpdatesHistory
This commit is contained in:
Aleksandr Chebotov
2021-11-16 17:14:17 +03:00
committed by GitHub
parent 1b583e05e5
commit df27520b1f
5 changed files with 110 additions and 18 deletions

View File

@@ -489,3 +489,47 @@ function Get-AndroidPackagesByVersion {
$packagesByVersion = $packagesByName | Where-Object { ($_.Split($Delimiter)[$Index] -as $Type) -ge $MinimumVersion }
return $packagesByVersion | Sort-Object { $_.Split($Delimiter)[$Index] -as $Type} -Unique
}
function Get-WindowsUpdatesHistory {
$allEvents = @{}
# 19 - Installation Successful: Windows successfully installed the following update
# 20 - Installation Failure: Windows failed to install the following update with error
# 43 - Installation Started: Windows has started installing the following update
$filter = @{
LogName = "System"
Id = 19, 20, 43
ProviderName = "Microsoft-Windows-WindowsUpdateClient"
}
$events = Get-WinEvent -FilterHashtable $filter -ErrorAction SilentlyContinue | Sort-Object Id
foreach ( $event in $events ) {
switch ( $event.Id ) {
19 {
$status = "Successful"
$title = $event.Properties[0].Value
$allEvents[$title] = ""
break
}
20 {
$status = "Failure"
$title = $event.Properties[1].Value
$allEvents[$title] = ""
break
}
43 {
$status = "InProgress"
$title = $event.Properties[0].Value
break
}
}
if ( $status -eq "InProgress" -and $allEvents.ContainsKey($title) ) {
continue
}
[PSCustomObject]@{
Status = $status
Title = $title
}
}
}