Forked from Chris-ZA/Delete Obsolete WSUS Updates.sql
Last active
February 6, 2018 21:12
-
-
Save meoso/38cd0310cb43adcc3163e3efd50fe697 to your computer and use it in GitHub Desktop.
Script to Delete Obsolete WSUS Updates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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) | |
PRINT 'Create table' | |
CREATE TABLE #ObsoleteUpdatesToCleanup (UpdateID INT) | |
PRINT 'insert table' | |
INSERT INTO #ObsoleteUpdatesToCleanup(UpdateID) EXEC spGetObsoleteUpdatesToCleanup | |
PRINT 'declare deletes' | |
DECLARE DeleteUpdates CURSOR FOR SELECT UpdateID FROM #ObsoleteUpdatesToCleanup | |
PRINT 'open deletes' | |
OPEN DeleteUpdates | |
PRINT 'fetch next' | |
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 | |
PRINT @message | |
EXEC spDeleteUpdate @localUpdateID=@UpdateID | |
FETCH NEXT FROM DeleteUpdates INTO @UpdateID | |
END | |
PRINT 'close deletes' | |
CLOSE DeleteUpdates | |
PRINT 'dealloc deletes' | |
DEALLOCATE DeleteUpdates | |
DROP TABLE #ObsoleteUpdatesToCleanup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
modified with
print
because it takes forever and unknown status of processing.also check https://community.spiceworks.com/how_to/103094-automate-wsus-cleanup