Search
  • Hans Kraaijeveld

VDI cleanup script - the decisive factor

Updated: May 5



Don't you just hate it, you have just built a VDI environment and rolled out your first production pool, and what do you see? Your host are all eating away CPU like there's no tomorrow until they are completely unavailable as a result!! Forgot to disable multiple automatic update services like Windows update itself, google and a few more? Also forgot to regenerate .NET? Now all these processes are running simultaneously on the same host(s), as all desktops are the same, since you cloned them...

When you are rolling out a cloned desktop pool like this, please do yourself a favor and create a cleanup script which you run at the end of your installation. Preferably automatic, as the last step in your rollout, but use it manually in any case to simply avoid these mishaps. Thanks to Lieven D’hoore's post from 2014 at Ituda, we can use his script to do a couple of things you should always do just before you create your snapshot. It is a collection of all items you can automate and should not forget. It's a bit long, but I'm stil listing it. I've added a few items from my own experience, like disabling the automatic update services and scheduled tasks that get added when you install Google Chrome. Another recent addition is the Windows Telemetry service in Windows 10, which uses both cpu and disk io to send Microsoft information about what's happening in that desktop. I'd suggest disabling this, unless you feel you really have to comply to this... Feel free to use this for your own environment, the script is listed here:

REM *********************

REM Force .net Runtime Optimization Service

REM *********************

%windir%\microsoft.net\framework64\v4.0.30319\ngen.exe update /force

REM *********************

REM Delete update tasks Google

REM *********************

SchTasks /Delete /TN "GoogleUpdateTaskMachineCore" /F

SchTasks /Delete /TN "GoogleUpdateTaskMachineUA" /F

REM *********************

REM Stop and disable Windows update service

sc stop wuauserv

sc config wuauserv start= disabled

REM *********************

REM Stop and disable Google update service

REM *********************

sc stop gupdate

sc config gupdate start= disabled

sc stop gupdatem

sc config gupdatem start= disabled

REM *********************

REM Stop and disable Windows Telemetry service

REM *********************

sc stop DiagTrack

sc config DiagTrack start= disabled

sc stop dmwappushservice

sc config dmwappushservice 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

REM on your initially created parent image and check all the boxes

REM of items you want to delete

REM *********************

c:\windows\system32\cleanmgr /sagerun:1

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 /f /t 0


2,203 views