/build/static/layout/Breadcrumb_cap_w.png

Uninstall windows update based on given date

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

This post is locked
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ