Loop through folder of multiple wim's

Discussion in 'Windows 8' started by hypedave, Nov 11, 2014.

  1. hypedave

    hypedave MDL Member

    Oct 14, 2014
    130
    30
    10
    #41 hypedave, Nov 18, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Thanks, is it possible to exclude wim files that are in the designated wim folder from being serviced?
     
  2. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,092
    24,400
    340
    #42 s1ave77, Nov 18, 2014
    Last edited by a moderator: Apr 20, 2017
    As always several ways to skin the cat :D.

    Hmm ... when mounting the WIMS you can exclude any of them by using the filename:

    Code:
    :: mount single WIMs to c:\images\mount, add updates, copy files and unmount/commit
    set path1=c:\images\files
    set target=c:\images\mount
    for /r "C:\images\wim" %%a in (*.wim) do (
    if /i %%~na equ Customer_XXX-11-01-2014 goto :endofmount
    if /i %%~na equ Customer_XXX-12-01-2014 goto :endofmount
    DISM /mount-wim /wimfile:%%a /index:1 /mountdir:C:\images\mount
    DISM /image:C:\images\mount /Add-Package /PackagePath:C:\images\wsusoffline\client\w63-x64\glb
    xcopy.exe %path1%\*.* %target%\*.* /s /d /e /h /r /k /y
    DISM /unmount-wim /mountdir:C:\images\mount /commit
    :endofmount
    )
    
    HINT: Where the runtime variable %%a inside the loop represents the full file path in our scenario, %%~na is the file name and %%~za is the extension :cool2:.


    EDIT: a TXT file (in same folder as WIMs) containing all excluded WIM names can be used for more comfort:

    Code:
    :: mount single WIMs to c:\images\mount, add updates, copy files and unmount/commit
    set path1=c:\images\files
    set target=c:\images\mount
    set textfile=c:\images\wim\exclusions.txt
    for /r "C:\images\wim" %%a in (*.wim) do (
        for /f "tokens=*" %%g in (%textfile%) do if not %%~na equ %%g (
            DISM /mount-wim /wimfile:%%a /index:1 /mountdir:C:\images\mount
            DISM /image:C:\images\mount /Add-Package /PackagePath:C:\images\wsusoffline\client\w63-x64\glb
            xcopy.exe %path1%\*.* %target%\*.* /s /d /e /h /r /k /y
            DISM /unmount-wim /mountdir:C:\images\mount /commit
        )
    )
    
    exclusions.txt would look:

    Code:
    Customer_XXX-11-01-2014
    Customer_XXX-12-01-2014
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Flipp3r

    Flipp3r MDL Guru

    Feb 11, 2009
    2,023
    977
    90
    #43 Flipp3r, Nov 18, 2014
    Last edited by a moderator: Apr 20, 2017
    Does that work for you? Does it matter what order the updates are installed?
    ie, your adding "Additional" before anything else...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,092
    24,400
    340
    #44 s1ave77, Nov 18, 2014
    Last edited: Nov 18, 2014
    Nice finding, didn't care for any order :g:. Should be baseline first and general, additional and extra as last.


    BTW: Cleaned the previously posted code.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. hypedave

    hypedave MDL Member

    Oct 14, 2014
    130
    30
    10
    Wow you guys rock, I was thinking of a text file way but you beat me to it. But here is a good one for you. Once the wim has been mounted and save how do we edit the code to the saved wim file name to the exclusion txt file?
     
  6. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,092
    24,400
    340
    #46 s1ave77, Nov 18, 2014
    Last edited by a moderator: Apr 20, 2017
    You want to add the name of every processed WIM to that list, correct?

    Code:
    :: mount single WIMs to c:\images\mount, add updates, copy files and unmount/commit
    set path1=c:\images\files
    set target=c:\images\mount
    set textfile=c:\images\wim\exclusions.txt
    for /r "C:\images\wim" %%a in (*.wim) do (
        for /f "tokens=*" %%g in (%textfile%) do if not %%~na equ %%g (
            DISM /mount-wim /wimfile:%%a /index:1 /mountdir:C:\images\mount
            DISM /image:C:\images\mount /Add-Package /PackagePath:C:\images\wsusoffline\client\w63-x64\glb
            xcopy.exe %path1%\*.* %target%\*.* /s /d /e /h /r /k /y
            DISM /unmount-wim /mountdir:C:\images\mount /commit
        )
    echo %%~na>>%textfile%
    )
    
    This will add the name to the list.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. hypedave

    hypedave MDL Member

    Oct 14, 2014
    130
    30
    10
    Thanks i'll report tomorrow my findings.
     
  8. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,092
    24,400
    340
    OK ... happy playing :D.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. hypedave

    hypedave MDL Member

    Oct 14, 2014
    130
    30
    10
    Issue 1 - if Patch folder is empty then DISM throws the error 87 code. Need to check if folder is empty then do not pass DISM command to apply packages.
    Issue 2 - Script not looking at the exclusion text file. Probably an error on my part. See code
    Issue 3 - Progress bars, this may be a hard one. Any way to implment progress bars?

    @echo off
    :: get admin rights
    (NET FILE||(powershell -command Start-Process '%0' -Verb runAs -ArgumentList '%* '&EXIT /B))>NUL 2>&1
    setLocal EnableDelayedExpansion

    :: Get timestamp data: will show month.day.year.hour.min.sec
    for /f "skip=1 delims=" %%x in ('wmic os get localdatetime') do if not defined X set X=%%x
    :: Timestamp with seconds
    :: set timestamp=%X:~4,2%-%X:~6,2%-%X:~0,4%-%X:~8,2%-%X:~10,2%-%X:~12,2%
    :: Timestamp without seconds
    set timestamp=%X:~4,2%-%X:~6,2%-%X:~0,4%-%X:~8,2%-%X:~10,2%
    :: Path to update packages
    set updates1=e:\windowsupdates\Baseline
    set updates2=e:\windowsupdates\General
    set updates3=e:\windowsupdates\Hotfix
    set updates4=e:\windowsupdates\Security
    set updates5=e:\windowsupdates\Additional
    set updates6=e:\windowsupdates\Extra
    :: Exclude WIms from
    set textfile=e:\wim\exclusions.txt

    :: Path to files copy
    set path1=e:\files
    set target=e:\mount

    :: start procedure
    :: backup all WIMs to e:\backup\backup.wim
    echo.
    echo ===============================================================================
    echo Backing up to e:\backup\backup_%timestamp%.wim
    echo ===============================================================================
    echo.
    set "p=0"
    for /r "e:\wim" %%a in (*.wim) do set /a p+=1
    if /i "%p%"=="0" echo NO WIMs FOUND.&&pause&&exit
    for /r "e:\wim" %%a in (*.wim) do (
    echo Exporting %%a to e:\backup\backup.wim
    echo.
    Dism /Export-Image /SourceImageFile:%%a /SourceIndex:1 /DestinationImageFile:e:\backup\backup_%timestamp%.wim /compress:max /CheckIntegrity
    )

    :: mount single WIMs to e:\mount, add updates and unmount/commit
    echo.
    echo ===============================================================================
    echo Mounting to e:\mount
    echo Adding Updates
    echo Unmount/Commit
    echo ===============================================================================
    echo.
    for /r "e:\wim" %%a in (*.wim) do (
    for /f "tokens=*" %%g in (%textfile%) do if not %%~na equ %%g (
    echo Processing %%a
    echo.
    DISM /mount-wim /wimfile:%%a /index:1 /mountdir:e:\mount
    DISM /image:e:\mount /Add-Package /PackagePath:%updates1%
    DISM /image:e:\mount /Add-Package /PackagePath:%updates2%
    DISM /image:e:\mount /Add-Package /PackagePath:%updates3%
    DISM /image:e:\mount /Add-Package /PackagePath:%updates4%
    DISM /image:e:\mount /Add-Package /PackagePath:%updates5%
    DISM /image:e:\mount /Add-Package /PackagePath:%updates6%
    xcopy.exe %path1%\*.* %target%\*.* /s /d /e /h /r /y
    DISM /unmount-wim /mountdir:e:\mount /commit
    )
    echo %%~na>>%textfile%
    )
    :: merge single WIMs to e:\master\install.wim
    echo.
    echo ===============================================================================
    echo Exporting to e:\master
    echo ===============================================================================
    echo.
    for /r "e:\wim" %%a in (*.wim) do (
    echo Exporting %%a to e:\master\install.wim
    echo.
    Dism /Export-Image /SourceImageFile:%%a /SourceIndex:1 /DestinationImageFile:e:\master\install.wim /compress:max /CheckIntegrity
    )

    :: split master WIM
    echo.
    echo ===============================================================================
    echo Splitting WIM to e:\sources
    echo ===============================================================================
    echo.
    Dism /Split-Image /ImageFile:e:\master\install.wim /SWMFile:e:\sources\install.swm /FileSize:256

    :: end procedure
    :: script will pause here
    echo.
    echo ===============================================================================
    echo DONE ...
    echo ===============================================================================
    echo.
    pause

    :: EXIT
    endlocal
    exit
     
  10. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,092
    24,400
    340
    #50 s1ave77, Nov 19, 2014
    Last edited by a moderator: Apr 29, 2017
    Code looks legit to me. In TXT file make sure only the name (without extension) is mentioned and there are no additional spaces at the end of the names.

    As said where in that case %%a is the full file path %%~na is the file name without extension, so make sure names match in files and TXT.

    BTW: better post code in [code=rich][/code] tags, else the post formatting will screw it by adding spaces to break long terms.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,092
    24,400
    340
    #51 s1ave77, Nov 19, 2014
    Last edited by a moderator: Apr 20, 2017
    Update presence checks:

    Code:
    :: mount single WIMs to e:\mount, add updates and unmount/commit
    echo.
    echo ===============================================================================
    echo Mounting to e:\mount
    echo Adding Updates
    echo Unmount/Commit
    echo ===============================================================================
    echo.
    set "a=0"&&set "b=0"&&set "c=0"&&set "d=0"&&set "e=0"&&set "f=0"
    for /r "%updates1%" %a in (*.*) do set /a a+=1
    for /r "%updates2%" %a in (*.*) do set /a b+=1
    for /r "%updates3%" %a in (*.*) do set /a c+=1
    for /r "%updates4%" %a in (*.*) do set /a d+=1
    for /r "%updates5%" %a in (*.*) do set /a e+=1
    for /r "%updates6%" %a in (*.*) do set /a f+=1
    for /r "e:\wim" %%a in (*.wim) do (
    for /f "tokens=* delims= " %%g in (%textfile%) do if not %%~na equ %%g (
    echo Processing %%a
    echo.
    DISM /mount-wim /wimfile:%%a /index:1 /mountdir:e:\mount
    if /i %a% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates1%
    if /i %b% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates2%
    if /i %c% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates3%
    if /i %d% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates4%
    if /i %e% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates5%
    if /i %f% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates6%
    xcopy.exe %path1%\*.* %target%\*.* /s /d /e /h /r /y
    DISM /unmount-wim /mountdir:e:\mount /commit
    )
    echo %%~na>>%textfile%
    )
    


    EDIT: to ignore eventual spaces at the end of names in TXT you can add a delimitter, see my edit.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,092
    24,400
    340
    Damn you're right the TXT loop is crap, needs to write all filenames to txt file then compare that file with exclusion and create a deltafile with the name of WIMs that will be processed.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  13. hypedave

    hypedave MDL Member

    Oct 14, 2014
    130
    30
    10
    #53 hypedave, Nov 19, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Something else has gone wrong to. Now after backing up the wims to backup.wim the script exits out and closes.

    Code:
    @echo off
    :: get admin rights
    (NET FILE||(powershell -command Start-Process '%0' -Verb runAs -ArgumentList '%* '&EXIT /B))>NUL 2>&1
    setLocal EnableDelayedExpansion
    
    :: Get timestamp data: will show month.day.year.hour.min.sec
    for /f "skip=1 delims=" %%x in ('wmic os get localdatetime') do if not defined X set X=%%x
    :: Timestamp with seconds
    :: set timestamp=%X:~4,2%-%X:~6,2%-%X:~0,4%-%X:~8,2%-%X:~10,2%-%X:~12,2%
    :: Timestamp without seconds
    set timestamp=%X:~4,2%-%X:~6,2%-%X:~0,4%-%X:~8,2%-%X:~10,2%
    :: Path to update packages
    set updates1=e:\windowsupdates\Baseline
    set updates2=e:\windowsupdates\General
    set updates3=e:\windowsupdates\Hotfix
    set updates4=e:\windowsupdates\Security
    set updates5=e:\windowsupdates\Additional
    set updates6=e:\windowsupdates\Extra
    :: Exclude WIms from 
    set textfile=e:\wim\exclusions.txt
    
    :: Path to files copy
    set path1=e:\files
    set target=e:\mount
    
    :: start procedure
    :: backup all WIMs to e:\backup\backup.wim
    echo.
    echo ===============================================================================
    echo Backing up to e:\backup\backup_%timestamp%.wim
    echo ===============================================================================
    echo.
    set "p=0"
    for /r "e:\wim" %%a in (*.wim) do set /a p+=1
    if /i "%p%"=="0" echo NO WIMs FOUND.&&pause&&exit
    for /r "e:\wim" %%a in (*.wim) do (
    echo Exporting %%a to e:\backup\backup.wim
    echo.
    Dism /Export-Image /SourceImageFile:%%a /SourceIndex:1 /DestinationImageFile:e:\backup\backup_%timestamp%.wim /compress:max /CheckIntegrity
    )
    :: mount single WIMs to e:\mount, add updates and unmount/commit
    echo.
    echo ===============================================================================
    echo Mounting to e:\mount
    echo Adding Updates
    echo Unmount/Commit
    echo ===============================================================================
    echo.
    set "a=0"&&set "b=0"&&set "c=0"&&set "d=0"&&set "e=0"&&set "f=0"
    for /r "%updates1%" %a in (*.*) do set /a a+=1
    for /r "%updates2%" %a in (*.*) do set /a b+=1
    for /r "%updates3%" %a in (*.*) do set /a c+=1
    for /r "%updates4%" %a in (*.*) do set /a d+=1
    for /r "%updates5%" %a in (*.*) do set /a e+=1
    for /r "%updates6%" %a in (*.*) do set /a f+=1
    for /r "e:\wim" %%a in (*.wim) do (
    for /f "tokens=* delims= " %%g in (%textfile%) do if not %%~na equ %%g (
    echo Processing %%a
    echo.
    DISM /mount-wim /wimfile:%%a /index:1 /mountdir:e:\mount
    if /i %a% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates1%
    if /i %b% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates2%
    if /i %c% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates3%
    if /i %d% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates4%
    if /i %e% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates5%
    if /i %f% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates6%
    xcopy.exe %path1%\*.* %target%\*.* /s /d /e /h /r /y
    DISM /unmount-wim /mountdir:e:\mount /commit
    )
    echo %%~na>>%textfile%
    )
    :: merge single WIMs to e:\master\install.wim
    echo.
    echo ===============================================================================
    echo Exporting to e:\master
    echo ===============================================================================
    echo.
    for /r "e:\wim" %%a in (*.wim) do (
    echo Exporting %%a to e:\master\install.wim
    echo.
    Dism /Export-Image /SourceImageFile:%%a /SourceIndex:1 /DestinationImageFile:e:\master\install.wim /compress:max /CheckIntegrity
    )
    
    :: split master WIM
    echo.
    echo ===============================================================================
    echo Splitting WIM to e:\sources
    echo ===============================================================================
    echo.
    Dism /Split-Image /ImageFile:e:\master\install.wim /SWMFile:e:\sources\install.swm /FileSize:256
    
    :: end procedure
    :: script will pause here
    echo.
    echo ===============================================================================
    echo DONE ...
    echo ===============================================================================
    echo.
    pause
    
    :: EXIT
    endlocal
    exit
    
     
  14. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,092
    24,400
    340
    #54 s1ave77, Nov 19, 2014
    Last edited by a moderator: Apr 20, 2017
    Stupid error ... see edit.

    Code:
    set "a=0"&&set "b=0"&&set "c=0"&&set "d=0"&&set "e=0"&&set "f=0"
    for /r "%updates1%" %%a in (*.*) do set /a a+=1
    for /r "%updates2%" %%a in (*.*) do set /a b+=1
    for /r "%updates3%" %%a in (*.*) do set /a c+=1
    for /r "%updates4%" %%a in (*.*) do set /a d+=1
    for /r "%updates5%" %%a in (*.*) do set /a e+=1
    for /r "%updates6%" %%a in (*.*) do set /a f+=1
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. hypedave

    hypedave MDL Member

    Oct 14, 2014
    130
    30
    10
    #55 hypedave, Nov 19, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    It's stuck in a loop of mounting the same WIM file and applying updates. It's ignoring the other wims but not moving to the next step of eporting them all to install.wim

    Code:
    :: mount single WIMs to e:\mount, add updates and unmount/commit
    echo.
    echo ===============================================================================
    echo Mounting to e:\mount
    echo Adding Updates
    echo Unmount/Commit
    echo ===============================================================================
    echo.
    set "a=0"&&set "b=0"&&set "c=0"&&set "d=0"&&set "e=0"&&set "f=0"
    for /r "%updates1%" %%a in (*.*) do set /a a+=1
    for /r "%updates2%" %%a in (*.*) do set /a b+=1
    for /r "%updates3%" %%a in (*.*) do set /a c+=1
    for /r "%updates4%" %%a in (*.*) do set /a d+=1
    for /r "%updates5%" %%a in (*.*) do set /a e+=1
    for /r "%updates6%" %%a in (*.*) do set /a f+=1
    for /r "e:\wim" %%a in (*.wim) do (
    for /f "tokens=* delims= " %%g in (%textfile%) do if not %%~na equ %%g (
    echo Processing %%a
    echo.
    DISM /mount-wim /wimfile:%%a /index:1 /mountdir:e:\mount
    if /i %a% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates1%
    if /i %b% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates2%
    if /i %c% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates3%
    if /i %d% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates4%
    if /i %e% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates5%
    if /i %f% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates6%
    xcopy.exe %path1%\*.* %target%\*.* /s /d /e /h /r /y
    DISM /unmount-wim /mountdir:e:\mount /commit
    )
    echo %%~na>>%textfile%
    )
    
    Code:
    @echo off
    :: get admin rights
    (NET FILE||(powershell -command Start-Process '%0' -Verb runAs -ArgumentList '%* '&EXIT /B))>NUL 2>&1
    setLocal EnableDelayedExpansion
    
    :: Get timestamp data: will show month.day.year.hour.min.sec
    for /f "skip=1 delims=" %%x in ('wmic os get localdatetime') do if not defined X set X=%%x
    :: Timestamp with seconds
    :: set timestamp=%X:~4,2%-%X:~6,2%-%X:~0,4%-%X:~8,2%-%X:~10,2%-%X:~12,2%
    :: Timestamp without seconds
    set timestamp=%X:~4,2%-%X:~6,2%-%X:~0,4%-%X:~8,2%-%X:~10,2%
    :: Path to update packages
    set updates1=e:\windowsupdates\Baseline
    set updates2=e:\windowsupdates\General
    set updates3=e:\windowsupdates\Hotfix
    set updates4=e:\windowsupdates\Security
    set updates5=e:\windowsupdates\Additional
    set updates6=e:\windowsupdates\Extra
    :: Exclude WIms from 
    set textfile=e:\wim\exclusions.txt
    
    :: Path to files copy
    set path1=e:\files
    set target=e:\mount
    
    :: start procedure
    :: backup all WIMs to e:\backup\backup.wim
    echo.
    echo ===============================================================================
    echo Backing up to e:\backup\backup_%timestamp%.wim
    echo ===============================================================================
    echo.
    set "p=0"
    for /r "e:\wim" %%a in (*.wim) do set /a p+=1
    if /i "%p%"=="0" echo NO WIMs FOUND.&&pause&&exit
    for /r "e:\wim" %%a in (*.wim) do (
    echo Exporting %%a to e:\backup\backup.wim
    echo.
    Dism /Export-Image /SourceImageFile:%%a /SourceIndex:1 /DestinationImageFile:e:\backup\backup_%timestamp%.wim /compress:max /CheckIntegrity
    )
    :: mount single WIMs to e:\mount, add updates and unmount/commit
    echo.
    echo ===============================================================================
    echo Mounting to e:\mount
    echo Adding Updates
    echo Unmount/Commit
    echo ===============================================================================
    echo.
    set "a=0"&&set "b=0"&&set "c=0"&&set "d=0"&&set "e=0"&&set "f=0"
    for /r "%updates1%" %%a in (*.*) do set /a a+=1
    for /r "%updates2%" %%a in (*.*) do set /a b+=1
    for /r "%updates3%" %%a in (*.*) do set /a c+=1
    for /r "%updates4%" %%a in (*.*) do set /a d+=1
    for /r "%updates5%" %%a in (*.*) do set /a e+=1
    for /r "%updates6%" %%a in (*.*) do set /a f+=1
    for /r "e:\wim" %%a in (*.wim) do (
    for /f "tokens=* delims= " %%g in (%textfile%) do if not %%~na equ %%g (
    echo Processing %%a
    echo.
    DISM /mount-wim /wimfile:%%a /index:1 /mountdir:e:\mount
    if /i %a% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates1%
    if /i %b% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates2%
    if /i %c% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates3%
    if /i %d% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates4%
    if /i %e% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates5%
    if /i %f% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates6%
    xcopy.exe %path1%\*.* %target%\*.* /s /d /e /h /r /y
    DISM /unmount-wim /mountdir:e:\mount /commit
    )
    echo %%~na>>%textfile%
    )
    :: merge single WIMs to e:\master\install.wim
    echo.
    echo ===============================================================================
    echo Exporting to e:\master
    echo ===============================================================================
    echo.
    for /r "e:\wim" %%a in (*.wim) do (
    echo Exporting %%a to e:\master\install.wim
    echo.
    Dism /Export-Image /SourceImageFile:%%a /SourceIndex:1 /DestinationImageFile:e:\master\install.wim /compress:max /CheckIntegrity
    )
    
    :: split master WIM
    echo.
    echo ===============================================================================
    echo Splitting WIM to e:\sources
    echo ===============================================================================
    echo.
    Dism /Split-Image /ImageFile:e:\master\install.wim /SWMFile:e:\sources\install.swm /FileSize:256
    
    :: end procedure
    :: script will pause here
    echo.
    echo ===============================================================================
    echo DONE ...
    echo ===============================================================================
    echo.
    pause
    
    :: EXIT
    endlocal
    exit
     
  16. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,092
    24,400
    340
    #56 s1ave77, Nov 19, 2014
    Last edited by a moderator: Apr 20, 2017
    After that crappy attempt now another one :cool2:.

    This time WIM names get written to TXT, then get compared against the exclusion list and if different will be written to delta TXT. The process stops if no differences were found, else it will proceed with files listed in delta TXT and names will be added to exclusions at the end.

    Next run would turn out no differences and will stop.

    Slighly complicated ... but should work that way.

    Code:
    @echo off
    :: get admin rights
    (NET FILE||(powershell -command Start-Process '%0' -Verb runAs -ArgumentList '%* '&EXIT /B))>NUL 2>&1
    setLocal EnableDelayedExpansion
    
    :: Get timestamp data: will show month.day.year.hour.min.sec
    for /f "skip=1 delims=" %%x in ('wmic os get localdatetime') do if not defined X set X=%%x
    :: Timestamp with seconds
    :: set timestamp=%X:~4,2%-%X:~6,2%-%X:~0,4%-%X:~8,2%-%X:~10,2%-%X:~12,2%
    :: Timestamp without seconds
    set timestamp=%X:~4,2%-%X:~6,2%-%X:~0,4%-%X:~8,2%-%X:~10,2%
    :: Path to update packages
    set updates1=e:\windowsupdates\Baseline
    set updates2=e:\windowsupdates\General
    set updates3=e:\windowsupdates\Hotfix
    set updates4=e:\windowsupdates\Security
    set updates5=e:\windowsupdates\Additional
    set updates6=e:\windowsupdates\Extra
    :: Exclude WIms from 
    set textfile=e:\wim\exclusions.txt
    
    :: CHECK FOR FILES TO PROCESS OR EXIT
    :: set compare files
    set "wimfile=e:\wim\wimlist.txt"
    set "deltafile=e:\wim\deltalist.txt"
    if exist %wimfile% del /s /q %wimfile% >nul
    if exist %deltafile% del /s /q %deltafile% >nul
    :: get WIM names from Folder
    for /r "f:\win\wim" %%a in (*.wim) do echo %%~na>>%wimfile%
    :: compare files and write difference to %deltafile%
    for /f "skip=3 tokens=1 delims= " %%a in ('powershell "Compare-Object -ReferenceObject (Get-Content %textfile%) -DifferenceObject (Get-Content %wimfile%)"') do echo %%a>>%deltafile%
    if not exist %deltafile% (
    echo No files to process found.
    echo:
    pause
    if exist %wimfile% del /s /q %wimfile% >nul
    exit
    )
    
    :: Path to files copy
    set path1=e:\files
    set target=e:\mount
    
    :: start procedure
    :: backup all WIMs to e:\backup\backup.wim
    echo.
    echo ===============================================================================
    echo Backing up to e:\backup\backup_%timestamp%.wim
    echo ===============================================================================
    echo.
    set "p=0"
    for /r "e:\wim" %%a in (*.wim) do set /a p+=1
    if /i "%p%"=="0" echo NO WIMs FOUND.&&pause&&exit
    for /r "e:\wim" %%a in (*.wim) do (
    echo Exporting %%a to e:\backup\backup.wim
    echo.
    Dism /Export-Image /SourceImageFile:%%a /SourceIndex:1 /DestinationImageFile:e:\backup\backup_%timestamp%.wim /compress:max /CheckIntegrity
    )
    :: mount single WIMs to e:\mount, add updates and unmount/commit
    echo.
    echo ===============================================================================
    echo Mounting to e:\mount
    echo Adding Updates
    echo Unmount/Commit
    echo ===============================================================================
    echo.
    set "a=0"&&set "b=0"&&set "c=0"&&set "d=0"&&set "e=0"&&set "f=0"
    for /r "%updates1%" %%a in (*.*) do set /a a+=1
    for /r "%updates2%" %%a in (*.*) do set /a b+=1
    for /r "%updates3%" %%a in (*.*) do set /a c+=1
    for /r "%updates4%" %%a in (*.*) do set /a d+=1
    for /r "%updates5%" %%a in (*.*) do set /a e+=1
    for /r "%updates6%" %%a in (*.*) do set /a f+=1
    :: execute loop for deltas only
    for /f "tokens=* delims= " %%a in (%deltafile%) do (
    echo Processing %%a
    echo.
    DISM /mount-wim /wimfile:e:\wim\%%a.wim /index:1 /mountdir:e:\mount
    if /i %a% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates1%
    if /i %b% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates2%
    if /i %c% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates3%
    if /i %d% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates4%
    if /i %e% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates5%
    if /i %f% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates6%
    xcopy.exe %path1%\*.* %target%\*.* /s /d /e /h /r /y
    DISM /unmount-wim /mountdir:e:\mount /commit
    echo %%a>>%textfile%
    )
    :: merge single WIMs to e:\master\install.wim
    echo.
    echo ===============================================================================
    echo Exporting to e:\master
    echo ===============================================================================
    echo.
    for /r "e:\wim" %%a in (*.wim) do (
    echo Exporting %%a to e:\master\install.wim
    echo.
    Dism /Export-Image /SourceImageFile:%%a /SourceIndex:1 /DestinationImageFile:e:\master\install.wim /compress:max /CheckIntegrity
    )
    
    :: split master WIM
    echo.
    echo ===============================================================================
    echo Splitting WIM to e:\sources
    echo ===============================================================================
    echo.
    Dism /Split-Image /ImageFile:e:\master\install.wim /SWMFile:e:\sources\install.swm /FileSize:256
    
    :: end procedure
    :: script will pause here
    echo.
    echo ===============================================================================
    echo DONE ...
    echo ===============================================================================
    echo.
    pause
    
    :: EXIT
    endlocal
    exit
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  17. hypedave

    hypedave MDL Member

    Oct 14, 2014
    130
    30
    10
    Ok let me give this one a shot
     
  18. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,092
    24,400
    340
    #58 s1ave77, Nov 19, 2014
    Last edited by a moderator: Apr 20, 2017
    One little refinement needed in delta TXT creation:

    Code:
    set "wimfile=e:\wim\wimlist.txt"
    set "deltafile=e:\wim\deltalist.txt"
    if exist %wimfile% del /s /q %wimfile% >nul
    if exist %deltafile% del /s /q %deltafile% >nul
    :: get WIM names from Folder
    for /r "f:\win\wim" %%a in (*.wim) do echo %%~na>>%wimfile%
    :: compare files and write difference to %deltafile%
    for /f "tokens=1 delims= " %%a in ('powershell "Compare-Object -ReferenceObject (Get-Content %textfile%) -DifferenceObject (Get-Content %wimfile%)" ^| findstr /i "=>"') do echo %%a>>%deltafile%
    if not exist %deltafile% (
    echo No files to process found.
    echo:
    pause
    if exist %wimfile% del /s /q %wimfile% >nul
    exit
    )
    
    
    Added:
    Code:
     ^| findstr /i "=>"
    to control the compare direction and deleted the skip as it is superseded by that.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  19. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,092
    24,400
    340
    #59 s1ave77, Nov 19, 2014
    Last edited by a moderator: Apr 20, 2017
    Last addition so far ... as you use an exclusion list you might want to backup/export only WIMs which are not part of that list :g:. Would need to use the same procedure for all loops:

    Code:
    @echo off
    :: get admin rights
    (NET FILE||(powershell -command Start-Process '%0' -Verb runAs -ArgumentList '%* '&EXIT /B))>NUL 2>&1
    setLocal EnableDelayedExpansion
    
    :: Get timestamp data: will show month.day.year.hour.min.sec
    for /f "skip=1 delims=" %%x in ('wmic os get localdatetime') do if not defined X set X=%%x
    :: Timestamp with seconds
    :: set timestamp=%X:~4,2%-%X:~6,2%-%X:~0,4%-%X:~8,2%-%X:~10,2%-%X:~12,2%
    :: Timestamp without seconds
    set timestamp=%X:~4,2%-%X:~6,2%-%X:~0,4%-%X:~8,2%-%X:~10,2%
    :: Path to update packages
    set updates1=e:\windowsupdates\Baseline
    set updates2=e:\windowsupdates\General
    set updates3=e:\windowsupdates\Hotfix
    set updates4=e:\windowsupdates\Security
    set updates5=e:\windowsupdates\Additional
    set updates6=e:\windowsupdates\Extra
    :: Exclude WIms from 
    set textfile=e:\wim\exclusions.txt
    
    :: CHECK FOR FILES TO PROCESS OR EXIT
    :: set compare files
    set "wimfile=e:\wim\wimlist.txt"
    set "deltafile=e:\wim\deltalist.txt"
    if exist %wimfile% del /s /q %wimfile% >nul
    if exist %deltafile% del /s /q %deltafile% >nul
    :: get WIM names from Folder
    for /r "f:\win\wim" %%a in (*.wim) do echo %%~na>>%wimfile%
    :: compare files and write difference to %deltafile%
    for /f "skip=3 tokens=1 delims= " %%a in ('powershell "Compare-Object -ReferenceObject (Get-Content %textfile%) -DifferenceObject (Get-Content %wimfile%)" ^| findstr /i "=>"') do echo %%a>>%deltafile%
    if not exist %deltafile% (
    echo No files to process found.
    echo:
    pause
    if exist %wimfile% del /s /q %wimfile% >nul
    exit
    )
    
    :: Path to files copy
    set path1=e:\files
    set target=e:\mount
    
    :: start procedure
    :: backup all WIMs to e:\backup\backup.wim
    echo.
    echo ===============================================================================
    echo Backing up to e:\backup\backup_%timestamp%.wim
    echo ===============================================================================
    echo.
    set "p=0"
    for /r "e:\wim" %%a in (*.wim) do set /a p+=1
    if /i "%p%"=="0" echo NO WIMs FOUND.&&pause&&exit
    for /f "tokens=* delims= " %%a in (%deltafile%) do (
    echo Exporting %%a to e:\backup\backup.wim
    echo.
    Dism /Export-Image /SourceImageFile:e:\wim\%%a.wim /SourceIndex:1 /DestinationImageFile:e:\backup\backup_%timestamp%.wim /compress:max /CheckIntegrity
    )
    :: mount single WIMs to e:\mount, add updates and unmount/commit
    echo.
    echo ===============================================================================
    echo Mounting to e:\mount
    echo Adding Updates
    echo Unmount/Commit
    echo ===============================================================================
    echo.
    set "a=0"&&set "b=0"&&set "c=0"&&set "d=0"&&set "e=0"&&set "f=0"
    for /r "%updates1%" %%a in (*.*) do set /a a+=1
    for /r "%updates2%" %%a in (*.*) do set /a b+=1
    for /r "%updates3%" %%a in (*.*) do set /a c+=1
    for /r "%updates4%" %%a in (*.*) do set /a d+=1
    for /r "%updates5%" %%a in (*.*) do set /a e+=1
    for /r "%updates6%" %%a in (*.*) do set /a f+=1
    :: execute loop for deltas only
    for /f "tokens=* delims= " %%a in (%deltafile%) do (
    echo Processing %%a
    echo.
    DISM /mount-wim /wimfile:e:\wim\%%a.wim /index:1 /mountdir:e:\mount
    if /i %a% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates1%
    if /i %b% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates2%
    if /i %c% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates3%
    if /i %d% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates4%
    if /i %e% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates5%
    if /i %f% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates6%
    xcopy.exe %path1%\*.* %target%\*.* /s /d /e /h /r /y
    DISM /unmount-wim /mountdir:e:\mount /commit
    echo %%a>>%textfile%
    )
    :: merge single WIMs to e:\master\install.wim
    echo.
    echo ===============================================================================
    echo Exporting to e:\master
    echo ===============================================================================
    echo.
    for /f "tokens=* delims= " %%a in (%deltafile%) do (
    echo Exporting %%a to e:\master\install.wim
    echo.
    Dism /Export-Image /SourceImageFile:e:\wim\%%a.wim /SourceIndex:1 /DestinationImageFile:e:\master\install.wim /compress:max /CheckIntegrity
    )
    if exist %wimfile% del /s /q %wimfile% >nul
    if exist %deltafile% del /s /q %deltafile% >nul
    
    :: split master WIM
    echo.
    echo ===============================================================================
    echo Splitting WIM to e:\sources
    echo ===============================================================================
    echo.
    Dism /Split-Image /ImageFile:e:\master\install.wim /SWMFile:e:\sources\install.swm /FileSize:256
    
    :: end procedure
    :: script will pause here
    echo.
    echo ===============================================================================
    echo DONE ...
    echo ===============================================================================
    echo.
    pause
    
    :: EXIT
    endlocal
    exit
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  20. hypedave

    hypedave MDL Member

    Oct 14, 2014
    130
    30
    10
    #60 hypedave, Nov 19, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    It's not processing any wims files at all.

    "No files to process"
    Press any key to continue

    Then it completely exits out the script.
    Code:
    @echo off
    :: get admin rights
    (NET FILE||(powershell -command Start-Process '%0' -Verb runAs -ArgumentList '%* '&EXIT /B))>NUL 2>&1
    setLocal EnableDelayedExpansion
    
    :: Get timestamp data: will show month.day.year.hour.min.sec
    for /f "skip=1 delims=" %%x in ('wmic os get localdatetime') do if not defined X set X=%%x
    :: Timestamp with seconds
    :: set timestamp=%X:~4,2%-%X:~6,2%-%X:~0,4%-%X:~8,2%-%X:~10,2%-%X:~12,2%
    :: Timestamp without seconds
    set timestamp=%X:~4,2%-%X:~6,2%-%X:~0,4%-%X:~8,2%-%X:~10,2%
    :: Path to update packages
    set updates1=e:\windowsupdates\Baseline
    set updates2=e:\windowsupdates\General
    set updates3=e:\windowsupdates\Hotfix
    set updates4=e:\windowsupdates\Security
    set updates5=e:\windowsupdates\Additional
    set updates6=e:\windowsupdates\Extra
    :: Exclude WIms from 
    set textfile=e:\wim\exclusions.txt
    
    :: CHECK FOR FILES TO PROCESS OR EXIT
    :: set compare files
    set wimfile=e:\wim\wimlist.txt
    set deltafile=e:\wim\deltalist.txt
    if exist %wimfile% del /s /q %wimfile% >nul
    if exist %deltafile% del /s /q %deltafile% >nul
    :: get WIM names from Folder
    for /r "e:\wim\wim" %%a in (*.wim) do echo %%~na>>%wimfile%
    :: compare files and write difference to %deltafile%
    for /f "skip=3 tokens=1 delims= " %%a in ('powershell "Compare-Object -ReferenceObject (Get-Content %textfile%) -DifferenceObject (Get-Content %wimfile%)" ^| findstr /i "=>"') do echo %%a>>%deltafile%
    if not exist %deltafile% (
    echo No files to process found.
    echo:
    pause
    if exist %wimfile% del /s /q %wimfile% >nul
    exit
    )
    
    :: Path to files copy
    set path1=e:\files
    set target=e:\mount
    
    :: start procedure
    :: backup all WIMs to e:\backup\backup.wim
    echo.
    echo ===============================================================================
    echo Backing up to e:\backup\backup_%timestamp%.wim
    echo ===============================================================================
    echo.
    set "p=0"
    for /r "e:\wim" %%a in (*.wim) do set /a p+=1
    if /i "%p%"=="0" echo NO WIMs FOUND.&&pause&&exit
    for /f "tokens=* delims= " %%a in (%deltafile%) do (
    echo Exporting %%a to e:\backup\backup.wim
    echo.
    Dism /Export-Image /SourceImageFile:e:\wim\%%a.wim /SourceIndex:1 /DestinationImageFile:e:\backup\backup_%timestamp%.wim /compress:max /CheckIntegrity
    )
    :: mount single WIMs to e:\mount, add updates and unmount/commit
    echo.
    echo ===============================================================================
    echo Mounting to e:\mount
    echo Adding Updates
    echo Unmount/Commit
    echo ===============================================================================
    echo.
    set "a=0"&&set "b=0"&&set "c=0"&&set "d=0"&&set "e=0"&&set "f=0"
    for /r "%updates1%" %%a in (*.*) do set /a a+=1
    for /r "%updates2%" %%a in (*.*) do set /a b+=1
    for /r "%updates3%" %%a in (*.*) do set /a c+=1
    for /r "%updates4%" %%a in (*.*) do set /a d+=1
    for /r "%updates5%" %%a in (*.*) do set /a e+=1
    for /r "%updates6%" %%a in (*.*) do set /a f+=1
    :: execute loop for deltas only
    for /f "tokens=* delims= " %%a in (%deltafile%) do (
    echo Processing %%a
    echo.
    DISM /mount-wim /wimfile:e:\wim\%%a.wim /index:1 /mountdir:e:\mount
    if /i %a% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates1%
    if /i %b% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates2%
    if /i %c% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates3%
    if /i %d% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates4%
    if /i %e% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates5%
    if /i %f% gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates6%
    xcopy.exe %path1%\*.* %target%\*.* /s /d /e /h /r /y
    DISM /unmount-wim /mountdir:e:\mount /commit
    echo %%a>>%textfile%
    )
    :: merge single WIMs to e:\master\install.wim
    echo.
    echo ===============================================================================
    echo Exporting to e:\master
    echo ===============================================================================
    echo.
    for /f "tokens=* delims= " %%a in (%deltafile%) do (
    echo Exporting %%a to e:\master\install.wim
    echo.
    Dism /Export-Image /SourceImageFile:e:\wim\%%a.wim /SourceIndex:1 /DestinationImageFile:e:\master\install.wim /compress:max /CheckIntegrity
    )
    if exist %wimfile% del /s /q %wimfile% >nul
    if exist %deltafile% del /s /q %deltafile% >nul
    
    :: split master WIM
    echo.
    echo ===============================================================================
    echo Splitting WIM to e:\sources
    echo ===============================================================================
    echo.
    Dism /Split-Image /ImageFile:e:\master\install.wim /SWMFile:e:\sources\install.swm /FileSize:256
    
    :: end procedure
    :: script will pause here
    echo.
    echo ===============================================================================
    echo DONE ...
    echo ===============================================================================
    echo.
    pause
    
    :: EXIT
    endlocal
    exit