How to successfully run SysPrep after using Desktop Experience feature
So you've installed Windows Server 2012 from scratch, patched it, installed your favorite apps on it, and then enabled Desktop Experience so you can run Disk Cleanup with all its features.
After removing that otherwise useless feature (useless in a Server, that is), you ran SysPrep and it failed with "A fatal error occurred while trying to sysprep the machine".
You're not alone. This has been happening for far too long, and I was unable to find a definitive guide on how to avoid this error.
I've read numerous forums about this issue, built a test VM in Hyper-V and created checkpoints (snapshots) every time I did something significant, analyzed sysprep log every time it failed, googled a little bit, restart from previous healthy checkpoint, rinse and repeat... Took me 2 whole working days to get to this conclusion and this is what I have found out:
SYSPREP WILL SUCCEED IF YOU:
- Install Server 2012R2 from scratch (I used en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso)
- Apply all available windows updates
- Create an user with administrative privileges
- Login with that user – do NOT log in with default administrator account
- Install other apps (SQL server, office, notepad++, putty, etc)
- Windows update again and again and again until no more updates show up
- Install Desktop Experience
- Prevent additional windows updates that only show up AFTER you install Desktop Experience
- Cleanup with Cleanmgr (this will take A LOT of time)
- Remove Desktop Experience
- Enter SysPrep audit mode (do not tick “generalize”)
- Remove user previously created (remember to select “delete files”)
- Run SysPrep (with generalize, if needed for your purpose)
The steps highlighted in bold holds the secret. To prevent those updates, I totally prevented the machine from even contacting Windows Update right after installing desktop experience, by disabling the NIC inside the VM. It is important that you do something similar, thus preventing windows update from even prestaging those updates. Don't worry, you won't need those updates, as they are related to something which you won't have in a server, anyway.
I have stumbled in several combinations of these and other steps where sysprep would fail. I will not post those, as my focus here is to provide a quick and straight forward tutorial on how to use cleanmgr without screwing up your hard worked image.
Just a quick note: the culprit seems to be the packages "winstore" and "immersivecontrolpanel" which get updated through Windows Update. These cannot be removed if installed from within the builtin Administrator account. If you add some other software, you *might* stumble in the same issue. Didn’t happen to me, but your mileage may vary.