I came across for the need to automating updates and filtering by Security & Monthly Rollup only using a PowerShell Script ;
This needs to be run as admin and does not require any module to be run;
It has been tested on Windows Server 2012/R2/2016
# To create the searcher we use new Object , we store the returned Searcher #object in the $Searcher variable
$Searcher = New-Object -ComObject Microsoft.Update.Searcher
#Create the session with MS update
$Session = New-Object -ComObject Microsoft.Update.Session
#UpdateCollection Object to Store Windows updates ID based on our criteria
$UpdateCollection = New-Object -ComObject Microsoft.Update.UpdateColl
# To install a software Update we need to search for the updated and add it to #the collection , download & install . we canuse Update Identity to easy #retrieve UpdateID
$results = $searcher.search("Type='software' AND IsInstalled = 0")
#$Results.Updates |
#ForEach-Object { $_.Identity.UpdateID ; "`t" + $_.Title }
#We Explore the results from object the previous Searcher and we define title #needs to be Security or Rollup!
$Results.Updates |
ForEach-Object{
if (($_.Title -like '*Preview of Monthly Quality Rollup for Windows Server*') -or ($_.Title -like '*Security Monthly Quality Rollup for Windows Server*'))
{
#echo "yes, found "
echo $_.Title
#echo $_.Identity.UpdateID
#Variable to Store identity of the Update ID
$updateID= $_.Identity.UpdateID
#Redefine Result with the wanted UPDATE ID
$Result = $Searcher.Search("UpdateID='$updateID'")
$Updates = $Result.updates
#We do Add to the Update collection
$UpdateCollection.Add($Updates.Item(0)) | out-null
# Creating the Downloader
$Downloader = $Session.CreateUpdateDownloader()
#Passing the collection to the downloader
$Downloader.Updates = $UpdateCollection
#Downloading Updates
$Downloader.Download()
# Creating The object Installer
$Installer = New-Object -ComObject Microsoft.Update.Installer
#Passing the Installer to the update collection
$Installer.Updates = $UpdateCollection
#Installing the Updates
$Installer.Install()
}
}