-
Notifications
You must be signed in to change notification settings - Fork 1
/
PendingUpdates.psm1
38 lines (36 loc) · 1.25 KB
/
PendingUpdates.psm1
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
$i18n = Data {
# culture="en-US"
ConvertFrom-StringData @'
PendingUpdates = Pending Windows Update
RebootRequired = Reboot required
'@
}
if ($PSUICulture -ne 'en-US') {
Import-LocalizedData -BindingVariable i18n
}
function Test($config) {
if ($PSVersionTable.PSEdition -eq 'Core' -and $PSVersionTable.Platform -ne 'Win32NT') {
$ruleName = [System.IO.Path]::GetFileNameWithoutExtension($PSCommandPath)
Write-UnsupportedPlatform($ruleName)
return
}
$updateSession = New-Object -ComObject Microsoft.Update.Session
$updateSession.ClientApplicationID = 'Windows Secure Auditor'
$updateSearcher = $updateSession.CreateUpdateSearcher()
$result = $updateSearcher.Search('IsHidden=0 and IsInstalled=0')
$exclude = $config.PendingUpdates.Exclude
$updates = $result.updates
if (-not [string]::IsNullOrWhiteSpace($exclude)) {
$updates = $updates | Where-Object { $_.KBArticleIDs -inotmatch $exclude }
}
if ($updates.Count -eq 0) {
return;
}
Write-Output "`n## $($i18n.PendingUpdates)`n"
foreach ($update in $updates) {
Write-CheckList $false $update.Title
if ($update.RebootRequired) {
Write-Output " - $($i18n.RebootRequired)"
}
}
}