The Deployment Bunny

OS Deployment, Virtualization, Microsoft based Infrastructure…

  • about.me

    about.me/mikaelnystrom

  • Archives

  • Meta

Nice to Know – Get rid of all junk before Sysprep and Capture when creating a reference image in MDT

Posted by Mikael Nystrom on June 5, 2014

Update: 2016-02-08

I have updated the script once more, current version is now 2.4.

https://github.com/DeploymentBunny/Files/blob/master/Tools/Action%20-%20Cleanup%20Before%20Sysprep/Action-CleanupBeforeSysprep.wsf

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

image

 

Modify the Task Sequence

Open your task sequence and before the Sysprep and capture step, something like this works fine.

image

 

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.

image
The patches you need.

 

Here you can see the Selection Profiles and the selection in one of them.

image
The Selection Profiles.

 

Here you can see how the modification in the Task Sequence.

image
The Task Sequence modification to inject the the correct patch to the correct OS.

/mike

134 Responses to “Nice to Know – Get rid of all junk before Sysprep and Capture when creating a reference image in MDT”

  1. ben said

    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

      • ben said

        Humm.. I’ll try a Win8.1 TS instead of Server 2012 TS to see if it works over there.

  2. ben said

    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

  3. Gary Blok said

    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 :-)

    • Gary said

      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”

      • ben said

        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

      • ben said

        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

  4. CLParker said

    Reblogged this on MDTGuy.WordPress.com and commented:
    SWEEEEEEEET!!!

  5. CLParker said

    Keep Up The Good Work! MDT Por Vida!

  6. Tony Dumas said

    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.

      • Tony Dumas said

        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.

      • Tony Dumas said

        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.

      • Tony Dumas said

        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.

      • Tony Dumas said

        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…

      • Tony Dumas said

        SUCCESS! I just watched the cleanup process run in the command window, and it completed successfully in about 3.5 minutes. :D

      • Great!

  7. […] Find the article here:  Nice to Know – Get rid of all junk before Sysprep and Capture when creating a reference image in… […]

  8. Rafael Vazquez said

    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,

  9. Adam said

    Hi, Mikael. Thank you for the script. Can this same script be ran at the end of an MDT Task Sequence in SCCM?

  10. MSB2014 said

    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?

      • MSB2014 said

        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.

  11. Bill said

    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

  12. Johan said

    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/

  13. 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.

  14. […] a nice tutorial here which when I just tried it shaved over 1GB off the overall size of my reference image. All credit […]

  15. Thomas said

    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

  16. […] Source […]

  17. Phil said

    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

    • Phil said

      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.

  18. itsRay said

    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.

  19. alexandrelizarov said

    Reblogged this on Блог ИТ специалиста and commented:
    Thank you very much! Today I tested your cleanup script!

    • alexandrelizarov said

      My result
      without deleting 8,62 Gb (9 261 333 675 bytes)
      after deleting 8,20 Gb(8 815 823 291 bytes)

  20. Oskar W said

    Using this to cleanup a “clean” windows 8.1 Enterprise reference image it shaved off about 1,4gigs!! Wow! Outstanding!

  21. Joe said

    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

      • Joe said

        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

      • Joe said

        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….

  22. Anders said

    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

  23. Helmut Daliot said

    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.

  24. Helmut Daliot said

  25. Andrew said

    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?

  26. Chris said

    Hi, Is there a command I can use outside of MDT to clear the WSUS updates and slim my reference image?

  27. ok, sad, get one of the books and you will be up within a couple of hours… :-)

  28. SauliusM said

    Hi, i can not download the script, Script download link is dead?

  29. Gavin said

    Will this be updated for Windows 10?

  30. Ty Glander said

    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 :)

  31. […] https://deploymentbunny.com/2014/06/05/nice-to-know-get-rid-of-all-junk-before-sysprep-and-capture-wh… […]

  32. Michael said

    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?

      • Michael said

        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.

  33. Karen Cervantes said

    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…

      • Karen Cervantes said

        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.

      • Karen Cervantes said

        Sorry, I meant: I added 2 ” restart computer ” steps previous to the script running action…

  34. 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.

  35. […] The story is here: https://deploymentbunny.com/2014/06/05/nice-to-know-get-rid-of-all-junk-before-sysprep-and-capture-wh&#8230;: […]

  36. JuliusPIV said

    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?

  37. Andrew said

    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 :-)

  38. Herve said

    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.

  39. Jonathan said

    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

  40. Saeid said

    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

  41. […] If this fixes the issue you are having it could be caused by a Windows update breaking the component store (as described in the following article). https://deploymentbunny.com/2014/06/05/nice-to-know-get-rid-of-all-junk-before-sysprep-and-capture-wh&#8230; […]

  42. […] https://deploymentbunny.com/2014/06/05/nice-to-know-get-rid-of-all-junk-before-sysprep-and-capture-wh&#8230; […]

  43. Caleb said

    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.

  44. Jonathan said

    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/

  45. […] (this applies to all OS’s, but since we only install 1 update for Win10, its not as crucial): https://deploymentbunny.com/2014/06/05/nice-to-know-get-rid-of-all-junk-before-sysprep-and-capture-wh&#8230; Update for high cpu/memory usage on WU scan in […]

  46. Ryan Andres said

    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.

  47. Ryan Andres said

    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.

      • Ryan Andres said

        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.

      • Alslinet said

        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

  48. Ryan Andres said

    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?

  49. Frank said

    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?

  50. […] compress the image. For Windows 8 + Windows 8.1 + Windows 10, you can skip step 2 to 6. Thanks to Mikael Nystrom blog post for the […]

  51. Andrew said

    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.

  52. cmiscloni said

    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 ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 7,427 other followers

%d bloggers like this: