You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.7 KiB
54 lines
1.7 KiB
2 years ago
|
# original script
|
||
|
# https://www.irisclasson.com/2018/12/27/using-powershell-to-summarize-pending-windows-updates-as-well-as-installed-updates/
|
||
|
|
||
|
$msUpdateSession = [activator]::CreateInstance([type]::GetTypeFromProgID("Microsoft.Update.Session",$env:COMPUTERNAME))
|
||
|
$updates = $msUpdateSession.CreateUpdateSearcher().Search("IsInstalled=0").Updates
|
||
|
|
||
|
$silverLightInstalled = Get-WindowsFeature | ? { $_.Name.ToLower() -like 'silverlight' }
|
||
|
|
||
|
$pendingUpdates = [System.Collections.ArrayList]@();
|
||
|
|
||
|
$output = "KB`tTitle`tDescription`tDate`tInfo";
|
||
|
|
||
|
foreach($u in $updates) {
|
||
|
$kb = $u.KBArticleIDs[0];
|
||
|
$title = $u.Title;
|
||
|
$desc = $u.Description;
|
||
|
$date = (Get-Date $u.LastDeploymentChangeTime).toString("yyyy-MM-dd");
|
||
|
$url = $u.MoreInfoUrls[0];
|
||
|
|
||
|
# make description a single line
|
||
|
$desc = $desc -replace "\n", " ";
|
||
|
|
||
|
if ($title.ToLower().Contains("silverlight")) {
|
||
|
if($silverLightInstalled) {
|
||
|
$pendingUpdates.Add($title)
|
||
|
}
|
||
|
} elseif ($title.ToLower().Contains("language pack")) {
|
||
|
# skip language packs
|
||
|
continue;
|
||
|
}
|
||
|
else {
|
||
|
$pendingUpdates.Add($title)
|
||
|
|
||
|
# add to the CSV output (tab-delimited)
|
||
|
$output += "`n$kb`t$title`t$desc`t$date`t$url";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$updatesCount = $pendingUpdates.Count
|
||
|
|
||
|
if($updatesCount -gt 0) {
|
||
|
Write-Host "***** $updatesCount updates pending*****" -BackgroundColor Black -ForegroundColor Yellow
|
||
|
$pendingUpdates | % { Write-Host $_ }
|
||
|
}
|
||
|
else {
|
||
|
Write-Host "***** No pending updates for $env:COMPUTERNAME*****" -BackgroundColor Black -ForegroundColor Green
|
||
|
}
|
||
|
|
||
|
# write csv
|
||
|
$ouput | Out-File ~\Documents\pendingupdates.csv
|
||
|
|
||
|
$outfp = (Resolve-Path ~\Documents\).Path
|
||
|
$outfn = $outfp + 'pendingupdates.csv'
|
||
|
Write-Host "Saved list to $outfn"
|