VMware Horizon View Recomposing – Don’t forget to cleanup after you finished

Linked/instant clone pools are recomposed on a regular basis. Mainly to install the monthly Windows updates and maybe also to upgrade/patch some applications installed on the parent VM.

Administrators often forget to cleanup the parent VM after they finished installing patches and before they take a new snapshot.

Copy the below lines into c:\windows\system32\vdi_cleanup.bat and run it each time you finished installing patches on your golden image.

REM *********************
REM Stop appvolume service
REM *********************
sc stop svservice
REM *********************
REM Stop and disable Windows update service
REM *********************
sc stop wuauserv
sc config wuauserv start= disabled
REM *********************
REM Delete any existing shadow copies
REM *********************
vssadmin delete shadows /All /Quiet
REM *********************
REM delete files in c:\Windows\SoftwareDistribution\Download\
REM *********************
del c:\Windows\SoftwareDistribution\Download\*.* /f /s /q
REM *********************
REM delete hidden install files
REM *********************
del %windir%\$NT* /f /s /q /a:h
REM *********************
REM delete prefetch files
REM *********************
del c:\Windows\Prefetch\*.* /f /s /q
REM *********************
REM Run Disk Cleanup to remove temp files, empty recycle bin
REM and remove other unneeded files
REM Note: Makes sure to run c:\windows\system32\cleanmgr /sageset:1 command on your initially created parent image and check all the boxes of items you want to delete 
REM *********************
c:\windows\system32\cleanmgr /sagerun:1
REM ********************
REM Execute queued compilation jobs for .NET Framework
REM ********************
cd c:\Windows\Microsoft.NET\Framework\v4.0.30319
ngen executequeueditems
REM ********************
REM Cleanup Image with DISM
REM ********************
dism.exe /online /cleanup-image /startcomponentcleanup /resetbase
REM ********************
REM CompactOS
REM ********************
compact /compactos:always
REM ********************
REM Defragment the VM disk
REM ********************
sc config defragsvc start= auto
net start defragsvc
defrag c: /U /V
net stop defragsvc
sc config defragsvc start= disabled
REM *********************
REM Clear all event logs
REM *********************
wevtutil el 1>cleaneventlog.txt
for /f %%x in (cleaneventlog.txt) do wevtutil cl %%x
del cleaneventlog.txt
REM *********************
REM release IP address
REM *********************
ipconfig /release
REM *********************
REM Flush DNS
REM *********************
ipconfig /flushdns
REM *********************
REM Shutdown VM
REM *********************
shutdown /s /t 0

6 Comments

  1. I am using this to prep a Gold Image for Windows 10 Enterprise 1607 OS 14393.1358 and at a certain point in the process (it flashes by too fast to see where) it goes to a solid blue screen with “please wait for the svservice” and hangs there. What do I need to edit to make this work properly on the above OS?

    1. The svservice is related to the App Volumes service. I have also seen that the App Volumes service sometimes sits there and does nothing when you bring a machine down. What I did to resolve it is:
      1. power cycle the VM
      2. uninstall the App Volumes agent
      3. reboot
      4. run the vdi_cleanup.bat script
      5. boot the VM
      6. install the App Volumes Agent
      7. reboot the VM
      8. run the vdi_cleanup.bat script

      1. This could also be because App Volumes is trying to communicate back to the server on shutdown with the IP released and the DNS flushed, I find it takes a very long time but it does go down. Very similar to starting up a system with the App Volumes client installed but the NIC shut off.

  2. After using this script almost every month (Windows 10) now it stops after
    vssadmin delete shadows /All /Quiet
    Using “start” or cmd /k is no solution so I commented it out for now

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.