Skip to content

Instantly share code, notes, and snippets.

@Chris-ZA
Last active February 6, 2018 20:53
Show Gist options
  • Save Chris-ZA/efe09d076fabb62153ca247d834bb5b2 to your computer and use it in GitHub Desktop.
Save Chris-ZA/efe09d076fabb62153ca247d834bb5b2 to your computer and use it in GitHub Desktop.
Script to Delete Obsolete WSUS Updates
-- This script deletes all obsolete WSUS updates from a WSUS database.
-- For more information, visit http://thebashfuladmin.com/2016/05/13/workaround-for-wsus-sql-timeout-errors/
USE SUSDB
DECLARE @UpdateID INT
DECLARE @message varchar(1000)
CREATE TABLE #ObsoleteUpdatesToCleanup (UpdateID INT)
INSERT INTO #ObsoleteUpdatesToCleanup(UpdateID) EXEC spGetObsoleteUpdatesToCleanup
DECLARE DeleteUpdates CURSOR FOR SELECT UpdateID FROM #ObsoleteUpdatesToCleanup
OPEN DeleteUpdates
FETCH NEXT FROM DeleteUpdates INTO @UpdateID WHILE (@@FETCH_STATUS > -1)
BEGIN SET @message = 'Deleting update ' + CONVERT(VARCHAR(10), @UpdateID) RAISERROR(@message,0,1) WITH NOWAIT
EXEC spDeleteUpdate @localUpdateID=@UpdateID
FETCH NEXT FROM DeleteUpdates INTO @UpdateID
END
CLOSE DeleteUpdates
DEALLOCATE DeleteUpdates
DROP TABLE #ObsoleteUpdatesToCleanup
@meoso
Copy link

meoso commented Feb 6, 2018

thanks, looks like the source blog disappeared

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment