Browse Source

Initial commit

master
Claire 3 months ago
parent
commit
290ac9b493
  1. 54
      Get-PendingUpdates.ps1

54
Get-PendingUpdates.ps1

@ -0,0 +1,54 @@
# 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"
Loading…
Cancel
Save