Update 2017-02-22
I can see a lot of comments about different versions and issues. Just to clarify, we use this script with the legacy version of Windows up to Windows Server 2016 (build 1607) and Windows 10 (build 1607). We have no issues with adding .NET Framework, since we do that before cleaning. We also have no issues adding anything else. There are some comments about “it takes time”, yes it does. Also, the script is “live”, that means that it will be a new version now and then. For the exact version and changes, please check GitHub.
/m
Update: 2016-02-08
I have updated the script once more, current version is now 2.4
https://github.com/DeploymentBunny/Files/tree/master/Tools/Action-CleanupBeforeSysprep
Fix No:1
There have been som issues with W8.1 and WS2012 R2 and it turns out that installling patches will allways make the component store “broken”. There seems to be a patch that mess it up. The fix is to run a repair of the store before compressing it. The script will now do that.
Fix No:2
The script did not recognice som operating system version and/or the log file did output incorrect information. The script now works with Windows 7 SP1 – Windows 10 and Windows Server 2008 R2 – Windows server 2016 TP4 (including Core editions).
Fix No:3
I relalized that there is no reason to keep the downlod patch cache, so that is now deleted in a correct way before capture. If you would like to keep that WSUS Client Cahce, open the script and remove the secion for each OS that does that part.
Update: 2016-01-24
Fix No:1
The script now uses a function that will popup the command windows so you can see the progress and if it gets stuck, it takes time to run it. The mopst important thing to remember is to reboot before you run the script, since all patches must be installed correctly, in some cases that might need to reboots, since a few patches doers require that (should not, but…)
The Story:
When you create a reference Image it will in most cases it will be updated with patches and some more patches and then some… That will make the image bigger and therefore the deployment of that image will take longer and consume more network resources. That can be corrected by getting rid of superseded patches, junk, temp files and much more. MDT does take care of much using the wimscript.ini during the capture process, but not all, not the old updates among other things.
The Solution
Since MDT is the preferred method to create reference images you can download the script, import it as an application and then run the application just before the Sysprep and Capture step. The Script works for the following versions of Windows:
- Windows 7 SP1
- Windows 8
- Windows 8.1 Update 1
- Windows 10
- Windows Server 2008 2 SP1
- Windows Server 2012
- Windows Server 2012 R2
- Windows Server 2016 TP 4
However, to make this work in Windows 7 and Windows Server 2008 R2 you need to add a hotfix to Packages in MDT. http://support.microsoft.com/kb/2852386
The script will use clenmgr.exe in all client versions of Windows. In Windows Server 2008 R2 it also uses clenmgr.exe, but it is never installed, instead it is copied from the SXS folder, that way we don’t need to install Desktop Experience. On Windows 8, Windows 10 and Server 2012 the script also runs the dism /online /clenup-image /startcomponentclenup and on 8.1 and server 2012 R2 the script adds the /Resetbase to make it impossible to remove patches.
Step By Step (kind of)
Download the script
Download the script from here http://1drv.ms/ThvLFE
Download the NEW Script from here: https://onedrive.live.com/?id=8563304F134DDCB6%211162216&cid=8563304F134DDCB6&group=0
Import it in MDT
Open the Deployment Workbench and browse to the Application node and import the folder you downloaded, giver it a name and as command line you type:
cscript.exe Action-CleanupBeforeSysprep.wsf
Modify the Task Sequence
Open your task sequence and before the Sysprep and capture step, something like this works fine.
Add the HotFix (only for Windows 7 SP1 and Windows Server 2008 R2)
You need to add the patches in the deployment workbench. If you would like the deployment of the reference image to a bit faster, create three folders put the correct patch in each folder and then create corresponding Selection Profiles and modify the Task Sequence to use them. You download the update here http://support.microsoft.com/kb/2852386
Here you can see the patches imported in the Deployment Workbench.
Here you can see the Selection Profiles and the selection in one of them.
Here you can see how the modification in the Task Sequence.
The Task Sequence modification to inject the the correct patch to the correct OS.
/mike
Categories: Deployment, MDT
I just set this up as you descibed it, but in runs forever and ever in my VM
i closed the CMD box and then the TS continues and fails…
Any hints?
I’ve uploaded my logs:
http://1drv.ms/1mimCnj
Yes, so the most common problem is that you need to do a reboot before, to make sure that there is no pending reboots from the patches. It is also possible that one or more patches was incorrectly installed or that they are broken/busted
Humm.. I’ll try a Win8.1 TS instead of Server 2012 TS to see if it works over there.
Mh, in Windows 8.1 i have the same “issue”
But maybe its not an issue.. Disk Cleanup is now running for 105 Minutes, but it still does something. Task Manager is showing a extreme high CPU / DISK utilization
Thanks, Added to my MDT built TS this morning, Worked perfect. Replaced the one I created last month that just adds those registry keys and ran cleanmgr.exe I like the logging feature you have in yours. Thanks so much.
NP :-)
Windows 7 worked perfect and very quick.
I just ran it on Windows 8.1 Took all night (700 Minutes) – It did finish and capture. Not sure why it would take so long though.
The process trimmed 300MB off of my WIM file.
About to run command: CleanMgr.exe /sagerun:5432 Action-CleanupBeforeSysprep 6/9/2014 2:40:54 PM 0 (0x0000)
Command has been started (process ID 2236) Action-CleanupBeforeSysprep 6/9/2014 2:40:54 PM 0 (0x0000)
ZTI Heartbeat: command has been running for 0 minutes (process ID 2236) Action-CleanupBeforeSysprep 6/9/2014 2:40:55 PM 0 (0x0000)
ZTI Heartbeat: command has been running for 700 minutes (process ID 2236) Action-CleanupBeforeSysprep 6/10/2014 2:20:00 AM 0 (0x0000)
Return code from command = 0 Action-CleanupBeforeSysprep 6/10/2014 2:20:29 AM 0 (0x0000)
Action-CleanupBeforeSysprep: Done Action-CleanupBeforeSysprep 6/10/2014 2:20:29 AM 0 (0x0000)
Seen that to, I think it is one of the patches that is making the “mess”
How many CPU’s did you assign your reference VM?
My Windows 8.1 took ~2 Hours with 2 VCPus on a SSD
2 is the perfect selection, and also run on SSD drives. On windows 8 it took a long time, but I have Office, App-v, UE-V, .NET 2/3/4/452 and WCF + all VC++ and all that ends up in lot of patches, so, yes it takes time to clean it up.
BTW, was it a 8.1 Update or the “old 8.1?
I use the 8.1 Update ISO
300mb in the WIM is ok, That is rather much when it comes to applying the image
I used a 8.1 ISO withouth the Update.
No Office installed, but also .NET + VCRedist Stuff.
However, i’m totally fine with 2+ Hours, if i KNOW the process takes that long :D
Reblogged this on MDTGuy.WordPress.com and commented:
SWEEEEEEEET!!!
Keep Up The Good Work! MDT Por Vida!
Is this made for MDT2012 or 2013? I can’t seem to get it to work in 2012 Update 1, and I have the update in place and the script running between reboots as recommended. It simply fails and I get a yellow warning on the summary screen.
It should work in any versions of MDT, it is using the DISM command in windows. There are reason for this to fail. For windows 7/2008R2 you need to have the hotfix in the image. For windows 8.1 it needs to be update may. You can open the vbscript and run the commands manually to se the error code.
I get no error messages running it in windows, simply nothing happens at all. in the Deployment Wizard the error says “Unable to set working directory (-2147024894)”. No log is generated during the TS either, so I can’t tell you what the problem there is. I am trying to run it in a TS for a Reference image of a Volume License edition of Win7 Pro SP1. No customizations at all…
1. Connect to the deployment share
2. Map the share as X:
3. Run cscript.exe \\server\deploymentshare\scripts\ztigather.wsf
4. Change directory to X:\Applications\The Folder for the application
5. run: cscript thescript.wsf file
That way you are emulating the way an application is running.
btw, have you checked the permissions in the folder where the script is located? A very common issue is that the account that is used by the deployment process does not have access to the folder or the script file, that could happens when you select to move the files while importing. If the file is on the desktop and you “move” it during import, the permissions is also moved and that will prohibit the script to run, due to incorrect permissions.
This is in the BDD.log:
Mandatory Single Application install indicated. Guid: {ba181745-291f-4625-bb88-b04528ac525a} ZTIApplications 6/9/2014 2:32:04 PM 0 (0x0000)
################ ZTIApplications 6/9/2014 2:32:04 PM 0 (0x0000)
Entry: {ba181745-291f-4625-bb88-b04528ac525a} ZTIApplications 6/9/2014 2:32:04 PM 0 (0x0000)
Name: TrueSec Cleanup Before Sysprep 1.0.1 ZTIApplications 6/9/2014 2:32:04 PM 0 (0x0000)
################ ZTIApplications 6/9/2014 2:32:04 PM 0 (0x0000)
Validating connection to \\192.168.24.13\Reference$\Applications\Cleanup ZTIApplications 6/9/2014 2:32:04 PM 0 (0x0000)
Already connected to server 192.168.24.13 as that is where this script is running from. ZTIApplications 6/9/2014 2:32:04 PM 0 (0x0000)
Change directory: \\192.168.24.13\Reference$\Applications\Cleanup ZTIApplications 6/9/2014 2:32:04 PM 0 (0x0000)
WARNING – unable to set working directory: (-2147024894) ZTIApplications 6/9/2014 2:32:04 PM 0 (0x0000)
Run Command: \\192.168.24.13\Reference$\Tools\X64\bddrun.exe cscript.exe Action-CleanupBeforeSysprep.wsf ZTIApplications 6/9/2014 2:32:04 PM 0 (0x0000)
ZTI installing application ZTIApplications 6/9/2014 2:32:04 PM 0 (0x0000)
About to run command: \\192.168.24.13\Reference$\Tools\X64\bddrun.exe cscript.exe Action-CleanupBeforeSysprep.wsf ZTIApplications 6/9/2014 2:32:04 PM 0 (0x0000)
Command has been started (process ID 2244) ZTIApplications 6/9/2014 2:32:04 PM 0 (0x0000)
Return code from command = 1 ZTIApplications 6/9/2014 2:32:05 PM 0 (0x0000)
Application TrueSec Cleanup Before Sysprep 1.0.1 returned an unexpected return code: 1 ZTIApplications 6/9/2014 2:32:05 PM 0 (0x0000)
Property InstalledApplications001 is now = {f0e483c5-3758-4306-b13a-807b333fc255} ZTIApplications 6/9/2014 2:32:05 PM 0 (0x0000)
Property InstalledApplications002 is now = {ba181745-291f-4625-bb88-b04528ac525a} ZTIApplications 6/9/2014 2:32:05 PM 0 (0x0000)
“WARNING – unable to set working directory: ” means that the account lacks permissions in the application folder.
I’m not sure if my issue is permissions-related, since other scripts that run do so normally. I’m also running on a basic VMware vm with 2 cpus and 4GB of RAM. All this reference task sequence does is just get Windows updates, nothing more. No applications, runtimes or any customizations at all. The 2852386 update is in the packages folder and in the correct task sequence. I know it is installing since I can run the disk cleanup wizard and see the new features that the update puts in there. I’m baffled…?
Have you checked the permissions on the file or folder? The log file very clearly says it cannot access the folder, so the script never runs.
The permissions are a match with the permissions for all the others in the Applications folder. BUT… I found that the folder I created when I imported the app does not match the “Working Directory” property for the application as it shows in the MDT console. I’ve corrected the folder name and I’m testing again…
SUCCESS! I just watched the cleanup process run in the command window, and it completed successfully in about 3.5 minutes. :D
Great!
As always, another very detailed write up on MDT. Awesome job. I used to this for different OSs using multiple steps with conditions targeting a specific operating system. I have now replaced all those steps with a single entry in my task sequence. Thank you!
In an unrelated note, if I may, we met at TechED 2014 in Houston last month (I’m the guy that won one of your awesome Viamonstra T-shirts during your pre-con session b.t.w) and you mentioned that you were going to create a post on your blog in regards to setting up a stand-alone WSUS server to be used with MDT. Are you still planning to do this?
If so, I’m really looking forward to it.
Thanks,
Thank you!
Yes, that post is in the “drawer”, ready to be posted soon. :-)
Hi, Mikael. Thank you for the script. Can this same script be ran at the end of an MDT Task Sequence in SCCM?
Yes!
Using this to install 8.1 enterprise… the script throws “invalid root in registry key” errors… had to try to run it manually to determine that. any thoughts?
No, are you using a EN-US based image?
Yes it is/was en-us based. Very strange deal related to something in the sequence that was causing the command prompt to not be elevated, so it was crashing because of permissions. I don’t understand WHY that was doing that, but was able to recreate the task sequence and have this work correctly.
HOWEVER, (and there’s always a “however”) I have found that when I capture an image after being prepped this way, it apparently isn’t dumping all the drivers properly. When I import the created .wim and re-apply the captured image to new hardware, it crashes with an asus .sys file (which IS appropriate for the build workstation, but NOT appropriate at all to be on the Dell laptop I’m applying to). If I disable this step, it applies without the driver being included… strange.
ok, so rule number one is to never, ever use physical hardware when creating a ref image. In this case it should not matter, since the sysprep process is the one that will get rid of all drivers, however, since it is a physical machine, there is likely to be hidden driver folders that will be captured and then used later when deployed, that is very common when the machine is an OEM machine. So, re-create the ref image in a VM and all your issues are gone.
Hi Mikael,
I implemented this on my MDT 2013 task sequences and it seems to be working fine for Windows 8.1 reference images, but not for Windows 2012 R2. (error 0x80004005 and Fatal error is returned in check for reboot request of the action (Action – Cleanup before Sysprep)). The issue I have though, is much weirder than this. Troubleshooting the problem, I deleted this step altogether from the task sequence and updated the deployment share and WinPE ISO images (even tried “Completely regenerate the boot images”). Still, when I try to create the Windows 2012 R2 reference image, I get the same error, even though this step is no longer part of the task sequence.
Please note that the error appears during the initial steps of the procedure, right after gather, so no actual task sequences are run. Also, I do this in a HYPER-V 2012 R2 Gen 2 VM.
You can check the error message below:
[IMG]http://i60.tinypic.com/24yzkg4.jpg[/IMG]
I appreciate any help,
Bill
Update: I deleted the task sequence and re-created it. This time it works flawlessly. Don’t know what went wrong the first time…
Bill
PS. Excellent script Mikael!
Thanks :-)
Use Gen 1 VM’s when creating Refs, it wont fix this issue, but it will avoid others.
Hi
Great post!
My action takes a lot of time I see cleanmgr two times in the deployment. Any reason for this?
See the pic for further details
http://www.ladda-upp.se/bilder/hrguejaecdanni/
It takes time, anything from 5 min to 30, even 60 minutes…
I’m seeing the same… two “Disk Cleanup” windows, but only one cleanmgr.exe process in Task Manager. Strange.
Yes, there are multiple actions running at the same time, some of them takes more time then other.
Reblogged this on mdtcmdeploy and commented:
Another really nice blog from Mikael , i always use the resetbase and cleanup when i create reference images in MDT to reduce the WIM file size. Always nice to have a small WIM if you have alot of DPs out there in the enviornment.
Hi Micke,
Is there no way to run the dism-command or something similar on win7? I’m runnig your script during at quite big (5.8GB) image build with Office, .NET, ect. but it only saves me 100MB.
No, the DISM command only works in Win8 or above, and yes it takes along time to get the crap out in Win7. Best tips is to create the ref image on SSD or on RAM disk using StarWind RAMdisk
Hi,
running the script on Server 2008 R2 SP1 is causing some problems here lettings the tasksequence end with errors. So far, wrapped in an application task, the script runs just fine on Windows 7 and 8 .
As advised for 2008 R2, i added the patches to the deployment process (same as to win7 x64).
For some reason the script does not recognize the OS Version and returns the following error when launched directly within the vm from my deployment share for troubleshooting:
“running on unknown os type”
Any idea what’s happening. How can i determine or influence the os version that my installation is signalizing during the task sequence?
Best, Phil
I got it fixed by changing two lines within the script to:
Line 256:
sExe = “C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.1.7600.16385_de-de_10da8b9bc379c09e\cleanmgr.exe.mui”
Line 257:
sFolder = “C:\Windows\System32\de-DE\”
I have no idea why the path in line 256 is different on my system as i made sure to download the us version of patch KB2852386. Has MS released another version of it or am i missing something here?
Changing the language folder in my case makes makes sense – so be aware of this potential need if you run a different language version.
A small tip: I initially took over the exact information on the details tab of the Application (first screenshot) but I noticed the TS just wouldn’t run the cleanup script properly (exit code 1). After changing the foldername (and with that, the working directory, to just .\Applications\cleanup, instead of a folder name with spaces in it) for the Application, things started working as expected.
Reblogged this on Блог ИТ специалиста and commented:
Thank you very much! Today I tested your cleanup script!
My result
without deleting 8,62 Gb (9 261 333 675 bytes)
after deleting 8,20 Gb(8 815 823 291 bytes)
Using this to cleanup a “clean” windows 8.1 Enterprise reference image it shaved off about 1,4gigs!! Wow! Outstanding!
:-)
If I already have the Windows 7 update cleanup hotfix applied via WSUS, do you need to apply the hotfix during as part of MDT? Also, I have a LTISuspend line when creating a reference machine AFTER WSUS runs. I’ve been simply then running disk cleanup, then resuming the task sqeuence. Is that the same thing as your script is doing? Just wondering if I can save even more space if I switch to your method :) thanks!
No, it does the same, but instead of doing it manually you can do it automatically, also you have one script that works for every OS supported by Microsoft
Thanks Mikael! Is there an ‘ultimate’ clean up script or anything for Windows 7 reference images? For example, I just deleted 600mb out of c:\windows\softwaredistribution\download before the capture process
Strange.. after using your script, the resulting .wim file was 100mb larger than the one I made last night, without script :\
Yes, that is strange, have not seen that, ever….
Hi, and thanks for making not so easy things easy!
I tried this action in my SCCM 2012 R2 Capture. It leaves no error in logs but it has been running for 3,5 hours with 0% CPU and no disk activity. I guess that when people say it takes time, the computer also has a workload the entire time?
Thanks
The time it takes depends on many things, but for a Windows 7 SP1 machine with the normal stuff, like Office, VC++, NET framework and so it takes around 2-4 hours depending on things like, patches locally, SSD drives, memory in the VM, number of CPUs and so on. However, i have never tested the script in ConfigMgr (it should work however) since i do all my ref images in MDT and then import the WIM into ConfigMgr
But you have a CPU load all the time during that 2-4 hours? I have no cpu load…
Hi, I already tried it on Windows 10! The script run without errors but also without results in size! I did not add the Hotfixes because I am not sure where I gan get those fixes for Windows 10 or if they are necessary? Attached see my logfile:
In order to make it smaller based on removing old patches, you need to install patches, otherwise there is nothing to do
There are not hotfixes needed for Windows 10, it works, but it is all about “old” patches, unless there are no old patches to remove, the gain is nothing, we see around 100-500 MB gain on Windows 10 currently, but it depends on many things like, was Office installed? Was C++ Runtimes installed, Did WU run and such.
Hi, and thank you for your valubale guides!
I was wondering. Is this (and the reset WSUS update counter trick) applicable to Windows 10 sysprep and capture scenarios as well?
Hi, i’m currently working with an update for W10
How is the work on an updated script for W10 going ?
You might be able to use the OSVersionNumber property since Left won’t work with the 4 digit number without more work:
sOSCurrentVersionShort = oEnvironment.item(“OSVersionNumber”)
Well, it does :-)
The new number is 10.
I have updated the script and are running tests. It works. The savings for Windows 10 is about 200 MB on the WIM file.
Hi, Is there a command I can use outside of MDT to clear the WSUS updates and slim my reference image?
Not really, the OS must be running to be able to figure out what to remove and cleanup.
The OS is running, I have just installed it long-hand and run windows update manually. Never quite got around to doing it all in MDT :(
ok, sad, get one of the books and you will be up within a couple of hours… :-)
Hi, i can not download the script, Script download link is dead?
I just tried to download and it works.
link doesnt work
Sorry, link has been updated
Do you have any script for shrinking SQL 2014 ?
My base image has grown by 1GB just by applying SQL Server 2014 SP2 CU2.
\resetbase etc made no difference
Thanks
Chris
Will this be updated for Windows 10?
Very nice work Mikael. I guess I didn’t take into account it just being case statements. After all the work to try and get 10 to be greater than 6 I sort of forgot about that :)
Hi Mikael.
Should this work with the new Windows 10 Release 1511 too?
I’m running a capture and it is running for 180 minutes now.
Has someone used this script with the new Windows 10 Iso allready?
Regards,
Michael.
Have not test it in 1511, it should work since nothing has changed. Did you add a reboot step before this step?
Yes a Restart is performed before cleanup.
I will watch the process, maybe it just takes some time.
I remember this was also the case with older Windows 7 Images, where we had to apply an update to fix it.
Maybe we need something similar here too.
Hi Mikael!
I’m running the script in the Windows 10 Release 1511 and it has been running for 274 minutes with 0% CPU and no disk activity. Nothing seems to be running. Just the CMD window and the Installation progress dialog are shown,
Regards,
Karen
Ok, yes, that seems a bit to long. They only thing that sometimes as a “Woops” is that it really needs a reboot before it starts working, its going trough all patches, and if there is a pending reboot it tries, but it fails on each and every patch. The script just runs standard built in commands in windows and they have been around for ever…
Thank you for your response.
I followed some of the recommendations you’ve given to us. In the task sequence I added 2 <> steps previous to the script running action and one more after that.
The settings for the virtual machine are the following:
– 4GB RAM
– 2 virtual processors
– Use Dynamic Memory… (Disabled)
– 60GB Virtual Hard Disk
Nothing seems to be working yet. The script has been running for more than 1000 minutes now.
See the pics for further details.
https://onedrive.live.com/redir?resid=9A9AC497B65318A9!4575&authkey=!AGHFrbdCtBdFR30&ithint=folder%2cpng
I think I’m going to manually run the commands in my Suspend Step.
Thank you again.
Regards.
Sorry, I meant: I added 2 ” restart computer ” steps previous to the script running action…
I’m also having problems with Windows 10 v1511. The action will continue to run forever. I have let it run over night without it completing. If I close the command window, it will complete the TS correctly though.
Ok, make sure you have a reboot before and a reboot after, depending on speed of disk it takes around 15 min up to 2 hours.
You can try to run it manully and you will see that the dism command takes a very long time if you are running on mechanical drive or a san, I ussaly run it on SSD drives or on RAM disk, also, make sure you VM is always built from ground up and has at least 4 GB of RAM, and whatever you do, never ever run using dynamic memory. The command that runs is just plain vanilla commands using dism.exe and clenmgr.exe, so there is no funky business at all
Ok. I’ll give that a shot. I did have my VM set to use dynamic memory, so I’ll try changing that and see if it helps.
Cheers.
I also tried again with more memory and turning off dynamic memory, and the heartbeet was over 300 minutes, before I closed the window. It seems to be the DISM step in the script that is taking so long, There has to be some incompatibility with 1511 and how it handles that DISM command. Have you been able to verify on your end?
I have done one minor modification to the script and that seems to solve the issue. I’ll test a couple of rounds more and then I’ll post an update.
I’m finding that in a Build & Capture of Windows 7, the cleanmgr consistently hangs on the ‘Windows Upgrade Log Files’ step. Everything prior to that (Windows ESD Installation FIles … Upgrade Discarded Files … Service Pack Cleanup etc.) works fine; it only ‘hangs’ on the ‘Windows Upgrade Log Files’ step.
Is anyone else seeing this?
Yes, and i’m working on that actully…
Mikael, I appreciate the confirmation and a huge thank you for this helpful script. Every little bit helps!
I just tried this on our Win10 REF-image (that also has Office 2016 installed) and this shaved about 200mb off my wim-file as well :-)
I captured Windows 7 SP1 Reference Image but WIM capture with Action-CleanupBeforeSysprep is bigger than without the script. Is it normal ? (Capture with MDT 2013 update 1 Release 2)
NO, that is not normal, since it is very close to impossible. The script removes a massive amount of files that is not captured. I’ll guess that there is something else that is the difference here.
I run this in my Windows 8.1 build and capture in MDT. When I try to deploy the image from SCCM it fails every time. It doesn’t get beyond the Apply O/S step. When I repeat the process with the script disabled in MDT, the captured image works fine in SCCM.
I’m investigating this, it seems to be a patch that destroys the entire sxs structure, have you tried to run the dism command manually after the image has been deployed?
I know it is a patch, just cant figure out the “one”…
/m
Same here, it takes for ever andfinally error out on DISM command
ran it on windows 8.1 with office 2010 and all versions of C++ installed.
I tokk it out of the TS and ran disk cleanup manually.
Thanks
I know, the problem is that there is one patch that breaks DISM /Cleanup (You cannot run it at all) so the only solution is to remove the DISM command from Win 8.1 and Windows Server 2012 R2, that is until I find the patch that ruins DISM /Cleanup from working
Is it just your script with the issues or can you not even manually run the DISM /cleanup?
You cannot run dism, ill post a new version of the script tomorrow morning, I have found a workaround to fix the broken cmp store
Trying to run the script from a TS on a VM with Win10 Ent 64bit…I am getting a note in the log that it is running on an unknown OS type…so obviously it is failing the OS detection somehow. For now I have simply isolated the section used to run on Win10 clients and have that in a separate script that runs. Any suggestions/fixes would be appreciated.
When detection is “unknown” it just skip that part. The latest version of the script should detect Windows 10 correctly.
Yeah I get that…I was using v2.4 already though.
Me too. Running on unknown on Windows 10 x64 Ent 10586.164
Ok, I’ll look into that!
I have a folder in Windows\SoftwareDistribution\Download\ that I (for some reason) do not have permission to as administrator, so the script just sits there until I exit the command prompt. http://postimg.org/image/5gv8hu9ih/
Hi Jonathan,
How have you solved it?
I have exactly the same problem.
Having an issue where the cleanup doesn’t complete and the heartbeat keeps counting. I’m at 1417 minutes on this one. If I close the command window, it doesn’t capture.
Yes, so, since the image is broken, DISM is trying to fix it, by replacing the files, that part does not show up in the log, but you can check the CBS and the DISM log file. If you close the command windows it did not finish the repair process. So, if you don’t run the script at all, well then it works, it should not, but it is kind of funny. If you check the health of the image is going to say “Hey, it is ok”, but you try to repair it, well then it says “Darn, its broken, trying to fix it”. Since we are compressing the image by removing stuff that are not in use, the image needs to be in perfect shape before we mess with it.
I am still having a problem with the script not completing and the heartbeat keeps going. In my last attempt, the heartbeat was at 1700+ minutes before I shutdown the VM. If I close the command window, the image does not capture. This is on a fully patched Windows 10 Image running in a VM.
It is not the script, it is the image that is broken, the DISM command fails if the image is broken. The question is why the image is broken and the most common reason is some kind of patch, update or pending reboot or similar. You can do a very simple test, halt the sequence and run the DISM command manually. But before doing that you should block Windows from getting updates by itself. You do that by changing ProtectPC in the customsettings.ini file to 3, also since it is Windows 10, download the latest patch and import it directly into packages.
Thanks for the heads up. I’ll give that a go.
Thanks. I didn’t know about the ProtectPC option. i set it in my unattend.xml, under oobe to 3. I am having difficulty finding the latest Windows 10 patch to import though… I’ll try the manual DISM method you suggested. Thanks for you help, it’s appreciated.
My component store is always broken as well due to Graphics card manufacturers replacing the opencl.dll file in windows. There is a reply from Microsoft in one of the TechNet forums where they state that its nothing to worry about though. But if it breaks dism commands its a big issue for me.
Agree, it should not be broken
I did a test and put a suspend step into my task sequence so I could run the steps manually. I ran the disk cleanup and then I did a DISM.exe /Online /Cleanup-Image /ScanHealth and that was successful, so I did a DISM.exe /Online /Cleanup-Image /StartComponentCleanup /ResetBase and that also completed successfully. Is there something else I should check?
I’ve had the command prompt hanging on C:\Windows\SoftwareDistribution\Download\3bc6d5a4702eb90277ddb74a3372a9fa\amd64_b5428c11c49c39633ea78b8dcf34f87b_b03f5f7f11d50a3a_6.3.9600.20708_none_98ebc1f2fcb78167.manifest for about 5 hours now. I’m going to wait a little while longer, but what logs can I look at? Is there anything I can do to fix?
Since the last patch tuesday this month i’ve been having some issues with this script. If i try to run the script sysprep fails with error message “Expected image state is IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE, actual image state is IMAGE_STATE_COMPLETE, sysprep did not succeed”.
The last lines in setupact.log in the Sysprep\Panther folder says:
==================================================================
2016-05-17 12:57:28, Error SYSPRP Package Microsoft.WindowsStore_2015.10.13.0_x64__8wekyb3d8bbwe was installed for a user, but not provisioned for all users. This package will not function properly in the sysprep image.
2016-05-17 12:57:28, Error SYSPRP Failed to remove apps for the current user: 0x80073cf2.
2016-05-17 12:57:28, Error SYSPRP Exit code of RemoveAllApps thread was 0x3cf2.
2016-05-17 12:57:28, Error [0x0f0082] SYSPRP ActionPlatform::LaunchModule: Failure occurred while executing ‘SysprepGeneralizeValidate’ from C:\Windows\System32\AppxSysprep.dll; dwRet = 0x3cf2
2016-05-17 12:57:28, Error SYSPRP SysprepSession::Validate: Error in validating actions from C:\Windows\System32\Sysprep\ActionFiles\Generalize.xml; dwRet = 0x3cf2
2016-05-17 12:57:28, Error SYSPRP RunPlatformActions:Failed while validating SysprepSession actions; dwRet = 0x3cf2
2016-05-17 12:57:28, Error [0x0f0070] SYSPRP RunExternalDlls:An error occurred while running registry sysprep DLLs, halting sysprep execution. dwRet = 0x3cf2
2016-05-17 12:57:28, Error [0x0f00d8] SYSPRP WinMain:Hit failure while pre-validate sysprep generalize internal providers; hr = 0x80073cf2
2016-05-17 12:57:28, Info [0x0f0052] SYSPRP Shutting down SysPrep log
2016-05-17 12:57:28, Info [0x0f004d] SYSPRP The time is now 2016-05-17 12:57:28
==================================================================
So it seems like it’s the AppxPackages that’s messing things up. I’ve run through the REF-Image task sequence a couple of times now and it seems like it’s fails on different packages each time.
If i disable the Windows Update steps in the REF-Image task sequence the script and sysprep/capture runs just fine without any errors.
I have tried to download the latest Windows 10 (1511) Enterprise media from VLSC. But it didn’t make any difference sadly. And ProtectYourPC is set to 3 in the Unattend.xml
And as I said, these problems started to appear after this month patch releases. I completed a REF-Image sysprep and capture last month with the exact same task sequence and script and that worked just fine.
I’m going to go through the last approved updates in the WSUS and see if I can’t find the guilty update.
Update: KB3156421 is the perpetrator. As soon as i try to include that update in the Win10 REF-image (combined with running the cleanup script) it fails, every time. For now I’ll just decline that update for the WSUS target Group I use for REF-image builds.
Thanks, I’ll look into this!
I’m seeing the same thing. Specifically, it looks like two specific files are causing the problem for me:
Oart.dll from KB3115084
and
d2d1.dll from KB3156421
My further notes are here:
https://social.technet.microsoft.com/Forums/en-US/28da3f9b-3ca1-4c7c-8236-02c552f7e9e6/10010586306-version-of-d2d1dll-problem?forum=win10itprosetup
Anyway, I don’t have a solution yet, I mean, beyond just not installing them.
(forgive me if I’ve submitted this twice.)
I’m seeing something similar. To me, it seems like there are two files that are causing problems:
Oart.dll from KB3115084
and
d2d1.dll from KB3156421
More is here:
https://social.technet.microsoft.com/Forums/en-US/28da3f9b-3ca1-4c7c-8236-02c552f7e9e6/10010586306-version-of-d2d1dll-problem?forum=win10itprosetup
No real solution, other than, not installing them before sysprepping (haven’t actually tried that yet).
Just thought i would report in. Im also experiencing the issues Andrew is seeing.
First of all, thank you for this wonderful script! It takes off up to 4.5GB in my case and is just a great tool to have. I’m just adding another tally mark for those seeing the issue reported by Andrew. I see on Github that only the latest and first versions of this script are available for download. Assuming 2.3 was not having this issue, it might be beneficial to swap out 2.4 for 2.3 in a Windows 10 Build and Capture TS to see what changes might be conflicting with those updates.
I have this running successfully on Windows 10 v1511 (10586), but I am having an issue on Windows 10 v1607 (14393). I have included the Cumulative Update KB3176929 as a package to deal with not getting any updates from WSUS, but I am experiencing the condition where the cleanup operation just keeps updating the heartbeat and never completes.
I will run the DISM commands manually on my next test, but I was wondering if anyone had done any testing on the Windows 10 Anniversary Edition just released?
I see always the same error when I use the cleanup script:
Error 1726 during the cleanup of Windows Update folder
Strange because it happens only when I have a snapshot in Vmware or a Control Point in HyperV !
Any idea ?
Hi, I’m trying to deploy golden image made using your script but am getting failure 5601: False: Verify OS guid {blah-blah-blah} exist, Litetouchdeployment failed, Return Code= -2147467259 0x80004005, Failed to run action Install Operating system. The password for this computer is not found in the local security database. (Error 000015E1; Source Windows).
Do you have any idea what’s going on? Windows got updated to latest KBs, drivers applied and that’s it. I also imported the KB you mentioned to MDT although when trying to install it under Windows it said it didn’t apply.
Windows 7 x64 Pro.
Thanks for your help.
Thanks for this! But will it break if I add a different language pack before the actual sysprep? Seems like it does. (v1607)
Dism fails (also when run by the script) on Windows 10 1607
None of the above KB’s are installed…
2016-09-19 09:02:27, Error DISM DISM Package Manager: PID=2740 TID=2164 Failed finalizing changes. – CDISMPackageManager::Internal_Finalize(hr:0x80070002)
2016-09-19 09:02:27, Error DISM DISM Package Manager: PID=2740 TID=2164 Failed processing package changes – CDISMPackageManager::StartComponentCleanupEx(hr:0x80070002)
2016-09-19 09:02:27, Error DISM DISM Package Manager: PID=2740 TID=2164 Failed to start component cleanup. – CPackageManagerCLIHandler::ProcessCmdLine_CleanupImage(hr:0x80070002)
2016-09-19 09:02:27, Error DISM DISM Package Manager: PID=2740 TID=2164 Failed while processing command cleanup-image. – CPackageManagerCLIHandler::ExecuteCmdLine(hr:0x80070002)
2016-09-19 09:02:27, Info DISM DISM Package Manager: PID=2740 TID=2164 Further logs for online package and feature related operations can be found at %WINDIR%\logs\CBS\cbs.log – CPackageManagerCLIHandler::ExecuteCmdLine
2016-09-19 09:02:27, Error DISM DISM.EXE: DISM Package Manager processed the command line but failed. HRESULT=80070002
Dism fails (also when run by the script) on Windows 10 1607
None of the above KB’s are installed…
2016-09-19 09:02:27, Error DISM DISM Package Manager: PID=2740 TID=2164 Failed finalizing changes. – CDISMPackageManager::Internal_Finalize(hr:0x80070002)
2016-09-19 09:02:27, Error DISM DISM Package Manager: PID=2740 TID=2164 Failed processing package changes – CDISMPackageManager::StartComponentCleanupEx(hr:0x80070002)
2016-09-19 09:02:27, Error DISM DISM Package Manager: PID=2740 TID=2164 Failed to start component cleanup. – CPackageManagerCLIHandler::ProcessCmdLine_CleanupImage(hr:0x80070002)
2016-09-19 09:02:27, Error DISM DISM Package Manager: PID=2740 TID=2164 Failed while processing command cleanup-image. – CPackageManagerCLIHandler::ExecuteCmdLine(hr:0x80070002)
2016-09-19 09:02:27, Info DISM DISM Package Manager: PID=2740 TID=2164 Further logs for online package and feature related operations can be found at %WINDIR%\logs\CBS\cbs.log – CPackageManagerCLIHandler::ExecuteCmdLine
2016-09-19 09:02:27, Error DISM DISM.EXE: DISM Package Manager processed the command line but failed. HRESULT=80070002
Hi guys just wondering has anyone tried to run this script after having kb3125574 convienance rollup pack for windows 7. seemed to skip past the task sequence step and do nothing. Worked on a windows 10 capture though.
Hello It works fine for Windows 10 build 1511 but with Build 1607 i get an Error 1726
When running the script to capture a Windows 10 image, the script always errors out around 70% when it runs the DISM /online /Cleanup-Image /StartComponenteCleanup /ResetBase command. The Error is 1726: The remote procedue call failed. Then when it runs the CleanMgr.exe /sagerun:5432, the Cleaning: Windows Update Cleanup and Scanning: Windows upgrade log files, tasks seem to run forever… I sat for an hour and a half waiting until I canceled them out. Other than that the script runs great!
Hi,
I keep getting an error on server 2016, is this not supported in server 2016 ?
“Application Action-CleanupBeforeSysprep returned an unexpected return code :1 “
I know, I need time to fix that, hopefully that will be this week
I’m also getting this error on MDT 2013. I see it in the deployment summary. It’s being run on a Windows 7 64 bit on VMware esxi 6.0. Is there an update for this?
Works like a Boss. Thank You
Server 2016 and Windows 10 1607. Fails with Event 41002 sent: ZTI ERROR – Non-zero return code by Action-CleanupBeforeSysprep, rc = 1.
Looking the log for this script it appears to finish but does not return something that the task sequence is looking for. It is listed as a warning on the task sequence.
This seems to affect both 2016 release and Windows 10 1607.
From the BDD.log
Action-CleanupBeforeSysprep: Return code from command = 1726 Action-CleanupBeforeSysprep 11/8/2016 12:15:46 PM 0 (0x0000)
Action-CleanupBeforeSysprep: Finished Action-CleanupBeforeSysprep 11/8/2016 12:15:46 PM 0 (0x0000)
ZTI ERROR – Non-zero return code by Action-CleanupBeforeSysprep, rc = 1 Action-CleanupBeforeSysprep 11/8/2016 12:15:46 PM 0 (0x0000)
Event 41002 sent: ZTI ERROR – Non-zero return code by Action-CleanupBeforeSysprep, rc = 1 Action-CleanupBeforeSysprep 11/8/2016 12:15:46 PM 0 (0x0000)
Return code from command = 1 ZTIApplications 11/8/2016 12:15:47 PM 0 (0x0000)
Application CleanUp Before Sysprep returned an unexpected return code: 1 ZTIApplications 11/8/2016 12:15:47 PM 0 (0x0000)
Event 41034 sent: Application CleanUp Before Sysprep returned an unexpected return code: 1 ZTIApplications 11/8/2016 12:15:47 PM 0 (0x0000)
I know, I need to fix that, with a bit of luck, that is tomorrow night…
oops sorry I didn’t see the other reports on this thread. Good stuff and thanks for responding.
Hi Mikael.
Did you manage to fix the issue? Experiencing the same on my Windows 10 1607 image. A few days before it was working fine.
working on it, trying to get more hours out of every day, but when you reach 24 it’s so hard to get more :-)
With Windows 10 1607 I can offer a temporary fix. (works although I do not understand why!)
1. Change the Cleanup Computer step (DISM.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase) to continue on error.
2. Right after insert a “Suspend”
3. Then, by hand and in an Administrative CMD, run the dism command “DISM.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase”
– It will go to 20% and then succeed.
4. Then Click on the Suspend to continue.
Works with updates and Office 2010, 2013 and 2016..
http://sccmdeploy.dk/?p=630
UPDATE:
With Windows 10 1607 I can offer a temporary fix. (works although I do not understand why!)
1. Change the “Cleanup Computer step (DISM.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase)” to “continue on error”.
2. Copy the Cleanup Computer step so that it in total runs three times right after each other.
3. The third can be run without “Continue on error” as it succeeds after 20%.
Thats it. Whole build including Office 2016 runs in less than three hours.
Hi Thomas,
I don’t understand exactly what you mean about your temporary fix…
Do we have to create 4 steps ?
1- Run command line (DISM.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase)” with “continue on error”
2- Run command line (DISM.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase)” with “continue on error”
3- Run command line (DISM.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase)” without “continue on error”
4- Execute script Action-CleanupBeforeSysprep.wsf
With “Restart computer” before and after.
Hi, just like to report its working for me for 1607 (OS Build 1493.447)
I’m using SCCM though with a ztigather before the cleanup script if that helps anyone.
Also using ztiwindowsupdate before that.
Under
‘ Windows 10
Case “10.”
I replaced
“if (iRetVal = 0) or (iRetVal = 3010) then”
With
“if (iRetVal = 0) or (iRetVal = 3010) or (iRetVal = 1726) then”
for both
‘Execute DISM.exe /online /Cleanup-Image /RestoreHealth
‘Execute DISM.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase
And that seems to have worked.
The cleanmgr for “Windows Upgrade Log Files” seems to take forever still though.
I’ve had trouble installing .NET 3.5 features after an OS was deployed as a result of the disk cleanup. I talked to MS support and they recommended not to do the /resetbase and /startcomponentcleanup. The workaround to get .NET 3.5 to install is an in-place OS upgrade (regrettably) which does work, as I was able to install .NET 3.5 after that. In my situation I was getting mapping index errors in the CBS.log file when NetFX3 feature would not install.
I got myself in this pickle when .NET 3.5 failed to install via MDT ‘Install Roles and Features’ task, I thought it had been deployed in my image for a while and realized it was not. My permanent fix for this is to ensure .NET 3.5 is installed first thing in my imaging process. I changed my workflow to enable NetFx3 offline into the latest MS media install.wim, then inject other OS patches offline before I do a boot up with that .WIM and perform MS Office install and capture a final image. Due to the uncertainty of future impact due to /resetbase and /startcomponentcleanup I am considering not doing this any longer, though it will result in larger .WIM sizes. Shrinking the .WIM was my motivation for doing it.
I’ve had trouble installing .NET 3.5 features after an OS was deployed as a result of the disk cleanup. I talked to MS support and they recommended not to do the /resetbase and /startcomponentcleanup. The workaround to get .NET 3.5 to install is an in-place OS upgrade (regrettably) which does work, as I was able to install .NET 3.5 after that. In my situation I was getting mapping index errors in the CBS.log file when NetFX3 feature would not install.
I got myself in this pickle when .NET 3.5 failed to install via MDT ‘Install Roles and Features’ task, I thought it had been deployed in my image for a while and realized it was not. My permanent fix for this is to ensure .NET 3.5 is installed first thing in my imaging process. I changed my workflow to enable NetFx3 offline into the latest MS media install.wim, then inject other OS patches offline before I do a boot up with that .WIM and perform MS Office install and capture a final image. Due to the uncertainty of future impact due to /resetbase and /startcomponentcleanup I am considering not doing this any longer, though it will result in larger .WIM sizes. Shrinking the .WIM was my motivation for doing it.
What is the status on this issue on Server 2016 ?
I am having issues with the script locking up while it is attempting to clean up the SoftwareDistribution folder. It reaches a particular manifest file and will sit there until I manually kill the script.
Great script, a must have in a B&C TS.
Bug report: Trying to run this on Swedish Windows 10 x64 1607 Education. OS is detected as unknown, which is obviously wrong…
As a temporary workaround, I’ve copy pasted the Win 10 steps for the unknown case in the script, which seems to work.
I am trying to run this scrip and getting an error: Return Code 1.
Does this script creates its own log? I am looking in bdd.log file, no information in smsts.log file as well.
The script used to work but is now failing with error 1726 when running “DISM.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase”. This is since I updated Windows 10 to the January 2017 version of build 1607. The only other change that I made was to fully patch Office 2016 (Not O365). Does anyone have a clue? Should I modify the script to continue on the error or could this cause future problems?
Is the download link working as I was having some issues?
I see other people have had the unknown OS issue. I am as well on Windows 10 1607. Any update on a fix for this?
One enhancement:
Add the Windows source variable (from MDT task sequence for example) and modifify the command line below to avoid erro: Dism not found Source of Windows :
sOSInstallSource = Left(oEnvironment.item(“WindowsSource”), (LEN(oEnvironment.item(“WindowsSource”))-3)) & “install.wim:1”
‘Execute DISM.exe /online /Cleanup-Image /RestoreHealth
oLogging.CreateEntry sActionName & “: Running DISM.exe /online /Cleanup-Image /RestoreHealth”, LogTypeInfo
iRetVal = oUtility.RunWithConsoleLogging(“DISM.exe /online /Cleanup-Image /RestoreHealth /Source:WIM:””” & sOSInstallSource & “”” /LimitAccess”)