Windows update removal during the test phase became hectic for Administrator. each update needs to be removed manually and it is time consuming.
This script will remove the update based on the specified date where windows update is installed.
$update = new-object -ComObject Microsoft.update.Session
$Collection = New-Object -ComObject Microsoft.Update.UpdateColl
$Searcher = $update.CreateUpdateSearcher()
$Installer = $Session.CreateUpdateInstaller()
$pending = $Searcher.Search("IsInstalled=1")
foreach($entry in $pending.Updates)
{
$installeddate= $entry.LastDeploymentChangeTime
$installeddate= $installeddate.ToShortDateString()
if ($installeddate -eq "7/10/2017" ) {
$Kb="KB",""
$B= $Kb -join $entry.KBArticleIDs
#$a+=$entry.KBArticleIDs
$TitlePattern=$B
$Searcher.QueryHistory(0, $Searcher.GetTotalHistoryCount()) |
Where-Object { $_.Title -match $TitlePattern } |
ForEach-Object {
Write-Verbose "Found update history entry $($_.Title)"
$SearchResult = $Searcher.Search("UpdateID='$($_.UpdateIdentity.UpdateID)' and RevisionNumber=$($_.UpdateIdentity.RevisionNumber)")
Write-Verbose "Found $($SearchResult.Updates.Count) update entries"
if ($SearchResult.Updates.Count -gt 0) {
$Installer.Updates = $SearchResult.Updates
$Installer.Uninstall()
$Installer | Select-Object -Property ResultCode, RebootRequired, Exception
}
}
}
}
Comments