PowerShell Script to Delete a specific update from WSUS
At time troubleshooting on cases we had to delete a specific update from the WSUS and we had done it through deleting it from database which is not a safe method.
This is also helpful at times when you want to remove a specific update and re-import the same from catalogue without a full clean up and sync
================================================================
#Change server name and port number and $True if it is on SSL
[String]$updateServer1 = "CMCAS"[Boolean]$useSecureConnection = $False
[Int32]$portNumber =8530#updateid (GUID of the update)to delete
$deleteupdate = "033189f3-6004-48f2-82f4-8d7fca20276d"# Load .NET assembly
[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
# Connect to WSUS Server
$updateServer = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($updateServer1,$useSecureConnection,$portNumber)
write-host "<<<Connected sucessfully >>>" -foregroundcolor "yellow"
$updatescope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$u=$updateServer.GetUpdates($updatescope )
foreach ($u1 in $u )
{
$a=New-Object Microsoft.UpdateServices.Administration.UpdateRevisionId
$a=$u1.id
if ($a.UpdateId -eq $deleteupdate)
{
write-host "Deleting update " $a.UpdateId "..."
$updateServer.DeleteUpdate($a.UpdateId)
}
}
trap
{
write-host "Error Occurred"
write-host "Exception Message: "
write-host $_.Exception.Message
write-host $_.Exception.StackTrace
exit
}
# EOF
==============================================================
This posting /Script is provided "AS IS" with no warranties and confers no rights
Comments
- Anonymous
February 28, 2015
Thanks - Anonymous
June 09, 2015
The comment has been removed - Anonymous
December 25, 2015
The comment has been removed