The following post was submitted by Jon Worley in response to a server stuck in a boot loop due to pending updates failing to install:
This is a summary of what I did to avoid manually removing 28 different packages using the long form name of them without access to Powershell in the Windows RE. This worked better than using DISM to revert pending actions or deleting “pending.xml” but takes a little additional prep work before running the script.
Pro tip: If it’s 2008 R2 and a VM, the mouse may not work so editing the file is easier when using shift + end to highlight text for deletion.
- Boot into the Windows RE from an ISO and launch into the command prompt recovery mode.
- Determine which drive has the image as it can vary by using “dir c:\, dir d:\, etc” until you find the system drive, in this case it was mounted to e:\
- If it doesn’t exist create a temp directory with “mkdir e:\temp”
- See if there are staged packages causing the hang up with:
“dism /image:e:\ /get-packages /scratchdir:e:\temp /format:table | more”
- If there are staged packages output them into a text file for easier manipulation with:
“dism /image:e:\ /get-packages /scratchdir:e:\temp /format:table >> e:\temp\packages.txt”
- This command can be run to trim out package names that are not in a “staged” state to reduce time
“findstr /v /i /c:”installed” /c:”superseded” /c:”not present” e:\temp\packages.txt > e:\temp\packages2.txt”
- From the command line run “notepad.exe” to launch a GUI to make editing easier then use file > open to locate and open “e:\temp\packages.txt” The output into the text file will look something similar to:
Package_for_RollupFix~31bf3856ad364e35~amd64~~14393.2007.1.8 | Installed | Security Update | 1/31/2018 8:19 PM
Package_for_KB4049065~31bf3856ad364e35~amd64~~10.0.1.3 | Staged | Update | 1/6/2018 2:17 AM
- All that we need from this document is to remove any line that is not showing “Installed” Once the only lines that remain show “Staged” the fluff has to be removed so that only the package name remains as so:
- When recovering the particular server in question there were 28 different updates that had to be removed to allow the server to boot:
- I was obviously NOT going to remove these one by one and type out these names so once I reduced the output to this point I used a simple loop to read through each line of text and pass it into DISM:
For /F “tokens=*” %i in (e:\temp\packages.txt) do dism /image:e:\ /remove-package /packagename:%i /norestart /scratchdir:e:\temp
Please note you might need to rename the “windows\winsxs\pending.xml” to “pending.old” in order to run DISM
Instead of spending 5-10 minutes typing in each command and package name I spent 20 minutes altering text and then kicked off the one-liner, came back 30 minutes later and it had finished. After a reboot server came back up!