Skip to main content

Recreating the SUSDB and WSUS Content folder for a Windows Server 2012 based WSUS computer

Credit to : https://blogs.technet.microsoft.com/sus/2016/10/18/recreating-the-susdb-and-wsus-content-folder-for-a-windows-server-2012-based-wsus-computer/

Occasionally you may find that you want to start over in WSUS with a fresh database (SUSDB). There can be any number of reasons for this, but typically I see people doing this if their SUSDB is rather old, has a ton of unneeded updates in it, and maintenance has not been done on the SUSDB in years. In those cases you can find that a rebuild may be faster and easier than fixing the problematic SUSDB. Typically speaking, I see people wanting to recreate the just the content dir if they accidentally unchecked the “download update files to this server only when updates are approved” and ended up with a hard drive full of unneeded files. Whatever the reason, here are the steps for recreating the SUSDB and the WSUS Content folder for a Windows Server 2012 based WSUS computer:
1. Open PowerShell as admin.
2. Stop the WSUS service and IIS Service with the following command:
stop-service WSUSService, W3SVC
Verify that both are stopped by running get-service WSUSService, W3SVC
It should look something like this:
clip_image001
3. Open SQL Server Management Studio and connect to the instance for SUSDB.
How you connect via SQL Server Management Studio is different depending on whether you installed SUSDB on Windows Internal Database (WID) or SQL Server. This was specified when you installed SUSDB. If you are not sure which you used, you can check a registry key on the WSUS server located at HKLM\Software\Microsoft\Update Services\Server\Setup to verify. Take a screenshot/registry export of this and look for the SQLServerName value. If you see just a server name or server\instance, you are using SQL server. If you see something that has the string ##SSEE or ##WID in it, you installed on Windows Internal Database, as demonstrated below:
Note that if you see ##SSEE, this blog post is not applicable to you.
clip_image003[1]
clip_image005[1]
If you installed SUSDB on Windows Internal Database (Not in my case)
If you installed SUSDB on Windows Internal Database (WID), you will need SQL Management Studio Express installed in order to remove the database. If you’re not sure which version of SQL Server Management Studio Express to install, here’s an easy way to figure that out:
For Windows Server 2012 and Windows Server 2012 R2, go to C:\Windows\WID\Log and find the error log that has the version number you’re using. Lookup the version number here:
321185 – How to determine the version, edition and update level of SQL Server and its components (https://support.microsoft.com/en-us/kb/321185)
This will tell you what Service Pack level it is running. Include the SP level when searching the Microsoft Download Center for SQL Management Studio Express as sometimes it does matter.
Once SQL Management Studio Express is installed, launch it and it will prompt you to enter the server name to connect to. If your OS is Windows Server 2012, use \\.\pipe\MICROSOFT##WID\tsql\query. Note that if you are not running Windows Server 2012 or 2012 R2, this blog post is not appropriate to use.
clip_image006[1]
Also note that for WID, you may want to run SQL Server Management Studio Express as administrator if you were not the person who installed WSUS.
If you did not install SUSDB on WID
If you did not install SUSDB on WID, simply type in the server name (\instance if needed):
clip_image008[1]
4. Backup the existing SUSB, just in case you need it later. Better safe than sorry ðŸ™‚
Open SQL –> expand databases –> right-click SUSDB, then select “New Query”.
Paste in the following, changing the directories to the directory of your choosing.
backup database [susdb] to disk =’D:\SQL\Backup\susdb.bak’ with copy_only
clip_image010[1]
5. Open SQL –> expand databases-> right-click SUSDB –> Delete. Be sure that you select “Close existing connections” at the bottom of the wizard.
Optionally, you can also delete the backups (delete is the default).
clip_image011[1]
6. Delete or rename the content directory, then recreate it. Please note that this will not delete/rename if the two services mentioned above are still running.
You can find the directory directory for the content folder by looking in HKLM\Software\Microsoft\Update Services\Server\Setup\ContentDIr *
Rename the directory by running REN WSUS WSUS_oldor delete it by running DEL WSUSthen confirm All with “A”:
clip_image013
clip_image014
Recreate the directory by running MKDIR WSUSNote that the default permissions will be reapplied when you run the post install.
clip_image015[1]
If you are not removing the SUSDB, but are removing the content and need to re-download files for updates you have already approved, do the following to initiate the download:
a. CD “C:\Program Files\Update Services\Tools”
b. Run .\WsusUtil.exe reset
clip_image016[1]
7. Start the services:
Start-service WSUSService, W3SVC
Verify that both are started by running get-service WSUSService, W3SVC
clip_image017
8. Reinstall the SUSDB by running the post install. The command varies depending on if you run WIDs or not.
First, CD to Program Files\Update Services\Tools.
For Full SQL (or non WIDS), run the following:
.\Wsusutil.exe postinstall SQL_INSTANCE_NAME=”Server\Instance” CONTENT_DIR=”<drive>:\WSUS”
clip_image019
For WIDS, run this:
.\Wsusutil.exe postinstall CONTENT_DIR=”<drive>:\WSUS”
clip_image021
General Post install notes
You need the “.\ “ in front of wsusutil.exe or it will not execute in PowerShell. For the default SQL instance, just type in the server name. You doneed the quotes in the above command. This will launch the post install which installs the SUSDB, recreates the website on port 8530 (default) and repoints everything to the ContentDir. The post install command will create a log in the <user>\AppData\Local\Temp directory which will be in the form of tmp*.tmp. This log may be 0kb for a little while. It will also spawn another log called WsusUtilUseCustomWebSite.log. The website log will disappear if all goes well with the website install, then the tmp*.log will be written to at that point. The tmp log will show you the tables, stored procedures, views, et cetera being created/verified in the SUSDB.
clip_image022[1]
clip_image023
After doing this, when you first launch the WSUS console, it will bring up the WSUS Configuration Wizard. You can run through this wizard if you would like and select your options such as products, upstream server and proxy. If you are using SSL, please note that additional configuration is required.
Hopefully you’ll never be faced with having to recreate your SUSDB. If you do, hopefully this will help make that process go as smoothly as possible.
Meghan Stewart, Support Escalation Engineer
Microsoft Enterprise Cloud Group