-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-WindowsUpdate.ps1
More file actions
48 lines (39 loc) · 2.17 KB
/
get-WindowsUpdate.ps1
File metadata and controls
48 lines (39 loc) · 2.17 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
48
function Get-WindowsUpdate {
[CmdletBinding()]
param (
[String[]] $ComputerName,
$Title = '*',
$Description = '*',
$Operation = '*'
)
$code = {
param
(
$Title,
$Description
)
$Type = @{
name='Operation'
expression={
switch($_.operation) {
1 {'Installed'}
2 {'Uninstalled'}
3 {'Other'}
}
}
}
$Session = New-Object -ComObject 'Microsoft.Update.Session'
$Searcher = $Session.CreateUpdateSearcher()
$historyCount = $Searcher.GetTotalHistoryCount()
$Searcher.QueryHistory(0, $historyCount) |
Select-Object Title, Description, Date, $Type |
Where-Object { $_.Title -like $Title } |
Where-Object { $_.Description -like $Description } |
Where-Object { $_.Operation -like $Operation }
}
$null = $PSBoundParameters.Remove('Title')
$null = $PSBoundParameters.Remove('Description')
$null = $PSBoundParameters.Remove('Operation')
Invoke-Command -ScriptBlock $code @PSBoundParameters -ArgumentList $Title, $Description
}
Get-WindowsUpdate