VMware OS Optimization Tool - Cleanup done right
Updated: Aug 4, 2022
When creating a clean and optimized image to deploy to your infrastructure in a VDI environment, it's essential you clean up. Everything in the image that is either incorrect, plain wrong or there for no reason, will be cloned x times. The bigger the environment, the bigger the spread of your mistakes.
Using this tool is just a small part of creating your image. If you want to know everything there is to know about creating a Golden Image for your VDI deployment, please make sure you visit and follow the steps in the official VMware Techzone guide:
Creating an Optimized Windows Image for a VMware Horizon Virtual Desktop
As a last step, just before creating the snapshot on which you are going to base your VDI pool, you should clean up after yourself. You could ofcourse do this manually, but to save a lot of time, I previously found and edited a script, which did a lot of good stuff for me automatically. I have posted this script quite some time ago in another blog post. This script however has become somewhat obsolete! The people behind the OSOT fling have not been twiddling their thumbs. Since the 1140 release, specific additions have been added to the tool, which make it even more invaluable to creating your pristine golden image: the cleanup is now part of the OSOT tool! They have called it: Finalize.
You can download it here, from the VMware Flings website:
When you run the Optimization Tool manually and want to clean your image, go to the Finalize tab:
Here, you can choose which items to use in Finalizing your image:
.NET framework optimization should always be done, especially if you have installed Windows Updates for .NET in the image. If you do not, this process will be started on all your VM's after deployment and could kill your environment from the massive CPU and memory usage.
The WinSxS folder is one that takes up a lot of space, cleaning this will result in a smaller base image.
Compacting will compress a number of files in the Operating System and will save you some more space. More information on this can be found in the Microsoft page about Compacting OS
Disk Cleanup will start the cleanmgr.exe and will delete loads of unnecessary files for you:
Compression of old files
Temporary Internet files
Temporary Windows files
Downloaded program files
Removal of unused applications or optional Windows components
Setup log files
Offline web pages (cached)
WinSxS (Windows component store)
Clearing the event logs makes troubleshooting that much easier. If you do not do this, the event log on every clone will contain entries from before the cloning action, which can be really distracting.
The SuperFetch Service is re-enabled by the Sysprep process, even though the OSOT tool turned it off on the optimize step. On a system with enough disk IO performance, there is not much to be had from this service and can therefore be disabled (again).
The Default User Profile is the hidden profile that is used everytime a new user account logs on to the system, to create a local profile for that user. The cleaner this profile, the faster logon will be. In a non-persistent VDI environment, this local profile creation always happens, as the desktop and profile on the desktop are removed at logoff. The default user profile is not relevant when using a roaming or mandatory profile, but you probably should refrain from either of these.
In the screenshot above, the option is red. I did not copy the SDelete64.exe to the system path or current working directory of the OSOT tool, hence the red text in the screenshot above. This tool zeroes out the unused blocks within the operating system's disk. This will result in a much smaller image when this VM is cloned. SDelete can be downloaded here.
LGPO is a small command-line utility released by Microsoft, which allows you to export and import local group policy easily.
KMS settings will be removed from the registry with this step. This is particularly useful when implementing this image in multiple different environments, where the KMS server should be locatable through DNS.
Flushing the DNS cache will help to remove any DNS resolving issues, as it forces the system to use a fresh DNS lookup, instead of using the local DNS cache.
The releasing the IP address option should be used with a bit of thought. In a graphically accelerated desktop image, removing the IP address will also remove any option to remotely connect to the machine. The vCenter console window will be blanked, and you will have no other option then to perform a remote shutdown. I usually deselect this option, so my remote connection stays intact in the event I need to do something else before shutdown.
The OSOT tool also allows use of it through command line, for automation purposes. This part, taken from the VMware fling site, shows the details on the Finalize step:
Performs tasks to clean up the system and clear information. These tasks are generally recommended to be run as the last step before shutting down to use the prepared master image in Horizon. These should also be used after a revision to the Windows image with application installation or update, or a Windows update process.
VMwareOSOptimizationTool.exe -finalize [all |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |10 |11]
all : Runs all of the tasks below.
0: Native Image Generator (NGEN). Optimizes the .NET Framework. Should be run after an update of .NET Framework.
1: Side by Side Component Cleanup (DISM). Reduces the size of the WinSxS folder by uninstalling and deleting packages with components that have been replaced by other components with newer versions. Should be run after a Windows update.
2: Compact. Enables CompactOS to compress specific Windows system files to free up space. Can take several minutes to execute.
3: Disk Cleanup. Deletes temporary and unnecessary files.
4: Clear system event logs
5: Disable Superfetch service
6: Clear default user profile
7: Zero empty disk space. (To enable this option, copy SDelete64.exe into the Windows\System32 or the current user directory).
8: Create local group policies. (To enable this option, copy LGPO.exe into the Windows\System32 or the current user directory).
9: Clear KMS Settings
10: Flush DNS cache
11: Release IP Address
Finalize running all of the tasks.
VMwareOSOptimizationTool.exe -finalize all
Finalize running NGEN to optimize .NET Framework and DISM to do a side by side component cleanup.
VMwareOSOptimizationTool.exe -finalize 0 1
If you want to read more about the Finalize step, the OSOT tool documentation will help you out. It can be found here.