Powershell – run Windows Update


#Windows Updates CLI

$UpdateSession = New-Object -ComObject 'Microsoft.Update.Session'
$UpdateSession.ClientApplicationID = 'PowerShell Sample'
$UpdateSearcher = $UpdateSession.CreateUpdateSearcher()

Write-Host 'Searching for updates...' -ForegroundColor Green
$SearchResult = $UpdateSearcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0")

if ($SearchResult.Updates.Count -ne 0)
{
Write-Host 'There are ' $SearchResult.Updates.Count 'applicable updates on the machine:' -ForegroundColor Green
}
else
{
Write-Host 'There are no applicable updates' -ForegroundColor Green
break
}
Write-Host 'Creating a collection of updates to download:' -ForegroundColor Green
$UpdatesToDownload = New-Object -ComObject 'Microsoft.Update.UpdateColl'
foreach ($Update in $SearchResult.Updates)
{
[bool]$addThisUpdate = $false
if ($Update.InstallationBehavior.CanRequestUserInput)
{
Write-Host "> Skipping: $($Update.Title) because it requires user input" -ForegroundColor Green
}
else
{
if (!($Update.EulaAccepted))
{
Write-Host "> Note: $($Update.Title) has a license agreement that must be accepted:"
$Update.EulaText
$strInput = Read-Host 'Do you want to accept this license agreement?
Continue Reading

Upgrade SCOM agents

Hi folks!

Recently I did SCOM upgrade with the latest Update Rollout and found some issues with SCOM agents. This is the first time when I use Windows Update rather than manual files download.…

Continue Reading