-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunScript - Update History.ps1
More file actions
47 lines (40 loc) · 1.95 KB
/
RunScript - Update History.ps1
File metadata and controls
47 lines (40 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Update History
# Lists all updates installed on system
# Varriables...
# Type: All, Successful, CurrentOnly
# More: https://social.technet.microsoft.com/wiki/contents/articles/4197.windows-how-to-list-all-of-the-windows-and-software-updates-applied-to-a-computer.aspx
Param(
[Parameter(Mandatory=$True)]
[string]$Type
)
Try {
If ($Type -eq "CurrentOnly") {
$Updates = Get-WmiObject -Class "win32_quickfixengineering"
# Output Results
$Updates | Select-Object -Property @{name="Title"; expression={$_.HotfixID}},
@{Name="Date"; Expression={([DateTime]($_.InstalledOn)).ToLocalTime()}},
@{name="Result"; expression={"Currently Installed"}},
@{name="Category"; expression={$_.Description}}
} ElseIf ($Type -eq "Successful") {
$Session = New-Object -ComObject "Microsoft.Update.Session"
$Searcher = $Session.CreateUpdateSearcher()
$HistoryCount = $Searcher.GetTotalHistoryCount()
$Updates = $Searcher.QueryHistory(0, $historyCount) | Where-Object {$_.Operation -eq 1 -and $_.ResultCode -eq 2}
# Output Results
$Updates | Select-Object Title, Date,
@{name="Result"; expression={If($_.ResultCode -eq 2){"Success"}else{$_.HResult}}},
@{name="Category"; expression={$_.Categories[0].Name}}
} Else {
$Session = New-Object -ComObject "Microsoft.Update.Session"
$Searcher = $Session.CreateUpdateSearcher()
$HistoryCount = $Searcher.GetTotalHistoryCount()
$Updates = $Searcher.QueryHistory(0, $historyCount) | Where-Object {$_.Operation -eq 1}
# Output Results
$Updates | Select-Object Title, Date,
@{name="Result"; expression={If($_.ResultCode -eq 2){"Success"}else{$_.HResult}}},
@{name="Category"; expression={$_.Categories[0].Name}}
}
} Catch {
Write-Output "Failed: $_"
Exit 1
}