CM12 R2's WSUS server's corrupted WID (windows Internal database)

You may face sometimes, issue with CM12 R2's WSUS server. It can be that the WID is corrupted and cannot be repaired.
Moreover the WSUS Service starts and stops after a while...
So you try to uninstall and re-install WSUS, but while performing the post-install operations, the following error is shown:

C:\Program Files\Update Services\Tools>wsusutil postinstall CONTENT_DIR="F:\WSUS"
Log file is located at C:\Users\sccmadmin\AppData\Local\Temp\tmp28B2.tmp
Post install is starting
Fatal Error: Not found

The following, are the available troubleshooting methods currently:

First of all, ensure that there is enough free disk space on the server.

Then, I have attached below the first method, based on this Technet blog post: https://blogs.technet.com/b/heyscriptingguy/archive/2013/04/15/installing-wsus-on-windows-server-2012.aspx
(try to follow it step-by-step)

Let’s start with the easiest, which is the WID database. I say easiest because it really comes down to just running a single line of code to get everything installed. Just to see what might be installed, I can use the WhatIf switch first.

Install-WindowsFeature -Name UpdateServices -IncludeManagementTools –WhatIf

From the looks of it, not only will WSUS be installed, but we also will be installing the WID database and some IIS components that are used for client check-ins and other things. I am confident that this is what I need, so let’s remove WhatIf and let it run again.

Wait for a bit…

 And we are now finished with the installation. As you can see, we have a message stating some additional configuration may be required before our WSUS server can be up and running. In this case, we still need to configure a location for the update files to be stored.

This is where wsusutil.exe will come into play. This executable is located at C:\Program Files\Update Services\Tools. Besides the usual parameters that you can use with this utility, there is another set of parameters that become available when you use the PostInstall argument.

.\wsusutil.exe postinstall /?

Note: If there is no WSUSUtil.exe in the Program Files\Update Services\Tools folder (in the Update Services folder) then the post install task will fail. Please check if exists. If not:
Please find WSUSUtil by searching for it on your Windows 2012 server > copy WSUSUtil into your newly created Tools folder in the Update Services folder.

We have parameters for specifying where to store the content and for where to build the database, if needed. Note that this can be used to specify a database that is local or remote (you will see this used on a remote system later).

Before I say where I want the content, I had better create a folder to store it. I don’t want all of this on my system drive, so I will create the folder on my D: drive.

New-Item -Path D: -Name WSUS -ItemType Directory

Now I can run the following command to configure my content directory to download and save all of the update files to D:\WSUS.

.\wsusutil.exe postinstall CONTENT_DIR=D:\WSUS

And with that, we have now configured the content directory on another drive to save the update files.

A second method, could be the following:

 ** Uninstall the WSUS role.

** Uninstall the WID role.

** Remove the SUSDB.

** Delete hklm\software\microsoft\update services registry key and WSUS directory from the drive.

** Clear out the WSUS mmc cache by deleting the WSUS folder under %appdata%\microsoft\mmc

** Restart the computer

** Reinstall WSUS from the server manager or, Re-install WSUS role using power shell command "Install-WindowsFeature -Name UpdateServices -IncludeManagementTools"

** Perform the post installation again using the Powershell command.

A 3d method, would be the following – attached below:
(based on this TechNet post: https://social.technet.microsoft.com/Forums/en-US/e1003863-e331-46da-8803-e8625bb6324b/server-2012-wsus-postdeployment-configuration-fails-comprehending-the-log-file?forum=winserverwsus )

Upon closer inspection the specifics of my error were right there for me, I just had to look at it long enough to decipher the details. What I now read is that Post-deployment configuration finds a file called UpdateServices-Services.xml (I found it in Windows\System32\ServerManager\ComponentConfiguration \). It determines that ContentLocal=Truewhich correctly indicates that my updates are to be stored locally. It proceeds to inquire about the ContentDirectory, but comes back without a value. Here are my UpdateServices-Services.xml file contents

<?xml version="1.0" encoding="utf-16"?><INSTANCE CLASSNAME="ServerComponent_UpdateServices_Services"><PROPERTY NAME="ContentDirectory" TYPE="string"></PROPERTY><PROPERTY NAME="ContentLocal" TYPE="boolean"><VALUE>true</VALUE></PROPERTY></INSTANCE>

I can see that the ContentLocalproperty did indeed have the value true , but the ContentDirectory property did not have a value . I now needed to figure out if a String value could be specified in the same way a Boolean value was, or if it needed quotes around it, or was supposed to be specified more like an attribute (learned about that somewhere along the way). I couldn't find any conclusive websites, and I didn't want to just try it for fear of the Post-deployment configuration running with an invalid ContentDirectory. Once again I returned to my log file and searched for answers at the https://go.microsoft.com/fwlink/?LinkId=235499 that was indicated. I didn't find any exact matches, but eventually I found a sample .xml file that specified a string value. It specified it as <VALUE>string</VALUE> with no brackets, so I knew to specify mine as <VALUE>C:\LocalMSUpdateCache</VALUE> and saved it. My UpdateServices-Services.xml now looks like this:

<?xml version="1.0" encoding="utf-16"?><INSTANCE CLASSNAME="ServerComponent_UpdateServices_Services"><PROPERTY NAME="ContentDirectory" TYPE="string"><VALUE>C:\LocalMSUpdateCache</VALUE></PROPERTY><PROPERTY NAME="ContentLocal" TYPE="boolean"><VALUE>true</VALUE></PROPERTY></INSTANCE>

I returned to Server Manager -> WSUS and re-attempted the Postdeployment configuration.

 

If all the above fail, please run the Process Monitor tool https://technet.microsoft.com/en-us/sysinternals/bb896645.aspx   – during the repro of the issue – and check the generated Process Monitor trace (so you know exactly where it is failing).

If all fail, this is the information for the OS in-place upgrade (this will also upgrade WSUS):

 Upgrade of the Site Server Operating System

Configuration Manager supports an in-place upgrade of the operating system of the site server in the following situations:

  • In-place upgrade to a higher Windows Server service pack as long as the resulting service pack level remains supported by Configuration Manager.
  • In-place upgrade from Windows Server 2012 to Windows Server 2012 R2.

https://technet.microsoft.com/en-us/library/gg682077.aspx#BKMK_UpgradeInfrastructure

 You will just have - before the upgrade - to stop and disable all of the ConfigMgr related services…

Then – after the OS upgrade – you may check if everything is ok and then, upgrade to the latest CM12 R2 CU.

  

Useful log files are located in the %temp% directory of the user who ran the installation process..