Windows Server 2012 R2 windows updates failing with error code 800f0831.
If any previous update is missing on the server then you will get the above error. To find the missing patch you have to check the CBS logs on the affected server and you will find the similar entries like below.
2020-04-29 04:21:03, Error CBS Failed to resolve package 'Package_8_for_KB4534309~31bf3856ad364e35~amd64~~220.127.116.11' [HRESULT = 0x800f0831 - CBS_E_STORE_CORRUPTION] 2020-04-29 04:21:03, Info CBS Mark store corruption flag because of package: Package_8_for_KB4534309~31bf3856ad364e35~amd64~~18.104.22.168. [HRESULT = 0x800f0831 - CBS_E_STORE_CORRUPTION]
Access the CBS log files on the affected computer from:
Search the CBS log files for Failed to resolve package or Mark store corruption flag and the missing KB is mentioned. Manually download and install that KB from catalog.update.microsoft.com. In my case it was KB4534309.
Restart the affected computer then try running Windows Updates again normally. Repeat the solution if you encounter the same error again, a new problem KB should be reported in the logs.
Lots of articles online suggest running the following then restarting. While these didn’t resolve my trouble you may have better success.
sfc /scannow dism /online /cleanup-image /scanhealth dism /online /cleanup-image /restorehealth
If you’re unable to get it resolved with the above steps feel free to firstname.lastname@example.org.