{"id":4884,"date":"2017-07-23T22:35:11","date_gmt":"2017-07-23T20:35:11","guid":{"rendered":"http:\/\/michlstechblog.info\/blog\/?p=4884"},"modified":"2021-04-28T07:59:52","modified_gmt":"2021-04-28T05:59:52","slug":"windows-cleanup-files-from-wsus-which-are-no-longer-needed","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/windows-cleanup-files-from-wsus-which-are-no-longer-needed\/","title":{"rendered":"Windows: Cleanup files from WSUS which are no longer needed"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_4884 social_share_privacy clearfix 1.6.4 locale-en_US sprite-en_US\"><\/div><div class=\"twoclick-js\"><script type=\"text\/javascript\">\/* <![CDATA[ *\/\njQuery(document).ready(function($){if($('.twoclick_social_bookmarks_post_4884')){$('.twoclick_social_bookmarks_post_4884').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"Windows%3A%20Cleanup%20files%20from%20WSUS%20which%20are%20no%20longer%20needed\",\"the_excerpt\":\"Hi%2C%0D%0A%0D%0Athe%20content%20of%20an%20WSUS%20Server%20crows%20every%20month%20for%20several%20GiBytes%20because%20WSUS%20does%20held%20all%20files%20which%20has%20the%20approval%20state%20%22install%22.%0D%0A%20%28more%26hellip%3B%29\",\"txt_info\":\"2 clicks for more data protection:\\r\\n\\r\\nOnly when you click here, the button will be come active and you can send your recommendation to Flattr. When activating, data are transmitted to third parties. \",\"perma_option\":\"off\"}},\"txt_help\":\"When you activate these fields by clicking, information to Flattr may be transferred abroad, and probably may also stored there.\",\"settings_perma\":\"Enable permanently and accept data transmission. \",\"info_link\":\"http:\\\/\\\/www.heise.de\\\/ct\\\/artikel\\\/2-Klicks-fuer-mehr-Datenschutz-1333879.html\",\"uri\":\"https:\\\/\\\/michlstechblog.info\\\/blog\\\/windows-cleanup-files-from-wsus-which-are-no-longer-needed\\\/\",\"post_id\":4884,\"post_title_referrer_track\":\"Windows%3A+Cleanup+files+from+WSUS+which+are+no+longer+needed\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p>Hi,<\/p>\n<p>the content of an WSUS Server crows every month for several GiBytes because WSUS does held all files which has the approval state &#8220;install&#8221;.<br \/>\n<!--more--><br \/>\nThe GUI way to cleanup the WSUS Content folder is to first decline all expired and superseded updates and than run the WSUS Cleanup Wizard.<\/p>\n<p>But you can also use the script way \ud83d\ude42<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n&#x5B;reflection.assembly]::LoadWithPartialName(&quot;Microsoft.UpdateServices.Administration&quot;)\r\n\r\n# Only needed if the script doesn't run on the WSUS Server\r\n&#x5B;String]$sWSUSServer = &quot;yourWSUSServer&quot;\r\n&#x5B;Boolean]$bSecureConnection = $False\r\n&#x5B;Int32]$iWSUSPort = 8531\r\ntry\r\n{\r\n       if(&#x5B;String]::IsNUllOrEmpty($sWSUSServer))\r\n       {\r\n            $oWSUSServer = &#x5B;Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer()\r\n       }\r\n       else\r\n       {\r\n\t    $oWSUSServer = &#x5B;Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer($sWSUSServer,$bSecureConnection,$iWSUSPort)\r\n       }\r\n}\r\ncatch &#x5B;Exception]\r\n{\r\n\twrite-warning (&quot;Cannot connect to WSUS Server: $sWSUSServer. Error: &quot; + $_)\r\n        exit 1\r\n}\r\n\r\n\r\n$oCleanUpManger=$oWSUSServer.GetCleanUpManager()\r\n\r\n$oCleanUpScope=new-object Microsoft.UpdateServices.Administration.CleanupScope\r\n$oCleanUpScope.DeclineSupersededUpdates=$true\r\n$oCleanUpScope.DeclineExpiredUpdates=$true\r\n$oCleanUpScope.CleanupUnneededContentFiles=$true\r\n$oCleanUpScope.CleanupLocalPublishedContentFiles=$true\r\n$oCleanUpScope.CleanupObsoleteUpdates=$false\r\n$oCleanUpScope.CompressUpdates=$false\r\n$oCleanUpScope.CleanupObsoleteComputers=$false\r\n\r\n$oCleanUpManger.PerformCleanup($oCleanUpScope)\r\n<\/pre>\n<p>Run the script<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nPS C:\\&gt; .\\WSUSCleanup.ps1\r\nSupersededUpdatesDeclined : 18\r\nExpiredUpdatesDeclined    : 0\r\nObsoleteUpdatesDeleted    : 0\r\nUpdatesCompressed         : 0\r\nObsoleteComputersDeleted  : 0\r\nDiskSpaceFreed            : 274123310463\r\n<\/pre>\n<p>Update:<br \/>\nNow there is also a Powershell command let which does the same job<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nPS C:\\&gt; Invoke-WsusServerCleanup -CleanupObsoleteUpdates -CleanupUnneededContentFiles -DeclineExpiredUpdates -DeclineSupersededUpdates\r\n<\/pre>\n<p>If you often got the &#8220;Reset Server Node Error&#8221; you should do a <a href=\"https:\/\/docs.microsoft.com\/en-us\/troubleshoot\/mem\/configmgr\/wsus-maintenance-guide\" rel=\"noopener\" target=\"_blank\">maintenance <\/a> task on your WSUS Database. Microsoft offers on <a href=\"https:\/\/docs.microsoft.com\/en-us\/troubleshoot\/mem\/configmgr\/reindex-the-wsus-database\" rel=\"noopener\" target=\"_blank\">SQL script<\/a> for this issue.<\/p>\n<p>You need the sqlcmd command line tool which is part of <a href=\"https:\/\/docs.microsoft.com\/de-de\/sql\/ssms\/download-sql-server-management-studio-ssms?view=sql-server-ver15\" rel=\"noopener\" target=\"_blank\">MSSQL Management Studio<\/a><\/p>\n<p>To start maintenance. Open a cmd shell as Administrator and execute the SQL Script. The database path is for a SQL Express installation. If you use an SQL Server you have to adjust it.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nC:\\&gt; sqlcmd -S np:\\\\.\\pipe\\MSSQL$MICROSOFT##SSEE\\sql\\query \u2013i D:\\temp\\WsusDBMaintenance.sql\r\n<\/pre>\n<p>Or just use the MSSQL Management Studio, connect to the database, open a query, copy the SQL Statement and execute it.<\/p>\n<p>Michael<\/p>\n<p>References<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-US\/troubleshoot\/mem\/configmgr\/wsus-maintenance-guide\" rel=\"noopener\" target=\"_blank\">Maintenance Guide<\/a><br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-US\/troubleshoot\/mem\/configmgr\/reindex-the-wsus-database\" rel=\"noopener\" target=\"_blank\">Reindex WSUS DB<\/a><br \/>\n<a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/69\/06\/Decline-SupersededUpdatesWithExclusionPeriod.ps1.txt\" rel=\"noopener\" target=\"_blank\">Decline-SupersededUpdatesWithExclusionPeriod.ps1<\/a><br \/>\nDecline-SupersededUpdatesWithExclusionPeriod.ps1 runs in <a href=\"https:\/\/docs.microsoft.com\/en-us\/troubleshoot\/mem\/configmgr\/wsus-maintenance-guide#running-the-decline-supersededupdateswithexclusionperiodps1-script-times-out-when-connecting-to-the-wsus-server-or-a-401-error-occurs-while-running\" rel=\"noopener\" target=\"_blank\">timeout or error 401<\/a><br \/>\nWSUS Cleaning wizard runs in <a href=\"https:\/\/docs.microsoft.com\/en-us\/troubleshoot\/mem\/configmgr\/wsus-maintenance-guide#troubleshooting\" rel=\"noopener\" target=\"_blank\">timeout<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, the content of an WSUS Server crows every month for several GiBytes because WSUS does held all files which has the approval state &#8220;install&#8221;.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[344,2,5],"tags":[1010,1079,1585,1080,583,1546,133,1586,1544,157,72,20,532,1545,1547],"class_list":["post-4884","post","type-post","status-publish","format-standard","hentry","category-powershell-scripting","category-windows","category-windowsknowhow","tag-cleanup","tag-content","tag-decline-supersededupdateswithexclusionperiod-ps1","tag-disk-space","tag-files","tag-maintenance-script","tag-powershell","tag-reindex","tag-reset-server-node","tag-save","tag-script","tag-windows-2","tag-wsus","tag-wsus-4","tag-wsusdbmaintenance-sql-script"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/4884","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/comments?post=4884"}],"version-history":[{"count":14,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/4884\/revisions"}],"predecessor-version":[{"id":7667,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/4884\/revisions\/7667"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=4884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=4884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=4884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}