Loop through folder of multiple wim's

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

  1. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #61 s1ave77, Nov 19, 2014
    Last edited: Nov 19, 2014
    Means no differences found (no delta TXT written) :g:.

    This time i checked the compare part and it's working here by showing the not excluded names (if all are recognized correctly). If a delta is found it should process further.

    Check if WIM names in exclusion eactly match the names in folder.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #62 s1ave77, Nov 19, 2014
    Last edited by a moderator: Apr 20, 2017
    :doh: ... little but devastating copy 'n paste error sneaked into compare part ... always good to check pathes 5 times not only 4 :D.

    instead of e:\wim\wim path should be e:\wim and it should work :g:.

    And "skip=3 tokens=* delims= " need to be changed to "tokens=1 delims= "

    Code:
    :: 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" %%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
    )
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    #63 hypedave, Nov 19, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    No errors out that DISM cant find file.

    the exclusion txt files looks like this

    Code:
    
    +
    +
    +
    Get-Content
    At
    +
    +
    +
    +
    Compare-Object
    At
    +
    +
    +
    +
    +
    +
    +
    Compare-Object
    At
    +
    +
    +
    +
    v1000_w81u1x64_Customer_001...
    v1000_w81u1x64_Customer_002...
    v1000_w81u1x64_Customer_003...
    
    
    Here is the code again
    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" %%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
    )
    
    :: 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
    
    
     
  4. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    Is still a problem in compare part. How is your original exclusion list looking like? The moment script pauses at end, wimfile and deltafile are still present, if you hit any key they get deleted.

    Please post exclusion list before start and the other 2 after the run (before thy get deleted).
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    That's the problem now, it's flying straight through and allowing the press any key to continue.
     
  6. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #66 s1ave77, Nov 19, 2014
    Last edited by a moderator: Apr 20, 2017
    Let's try a real dry run to check the compare.

    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" %%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
    )
    
    :: Path to files copy
    set path1=e:\files
    set target=e:\mount
    echo Exclusions:
    type %textfile%
    echo:
    echo:
    echo Folder:
    type %wimfile%
    echo:
    echo Delta:
    type %deltafile%
    :: end procedure
    :: script will pause here
    echo.
    echo ===============================================================================
    echo DONE ...
    echo ===============================================================================
    echo.
    pause
    
    :: EXIT
    endlocal
    exit
    Post the output.



    I tested with a folder with installa.wim, installb.wim (till d), exclusion list excludes b and c image. When runing above script it correctly outputs:

    Code:
    Exclusions:
    installb
    installc
    
    Folder:
    installa
    installb
    installc
    installd
    
    Delta:
    installa
    installd
    
    ===============================================================================
    DONE ...
    ===============================================================================
    
    Drücken Sie eine beliebige Taste . . .
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    Okay so I got curious and shortened the file name of the WIM and it's going through with no errors so far.
     
  8. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    Yeah, was assuming this being the error ... nice to hear it's working for you. Debugging can be kinda breech birth sometimes :cool2:.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    HINT: I now remember that using '()' in a filename (default for Total Commander when automatically renaming files during copy) causes powershell to error out. Seems there are some chars where it reacts bitchy :g:.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    welpI have the character _ in the wim file names.
     
  11. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    That one shouldn't cause errors affaik.

    Use my last dry-run-test script to check what's working, it will only show all found names, shorter than the whole process every time :cool2:.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    Rename one of your WIM to this (replaced the x's) but that you an idea of the character size.

    XXXXX_XXXXXXXX_XXXX_XXX_XXXXX_XX_XXX_XXXX_XXXX-11-17-2014.wim
     
  13. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #73 s1ave77, Nov 19, 2014
    Last edited by a moderator: Apr 20, 2017
    Seems to be no problem, even when using Xs, renamed one of he WIMs and added their name to exclusions.txt:

    Code:
    Exclusions:
    installa
    XXXXX_XXXXXXXX_XXXX_XXX_XXXXX_XX_XXX_XXXX_XXXX-11-17-2014
    
    Folder:
    installa
    installc
    installd
    XXXXX_XXXXXXXX_XXXX_XXX_XXXXX_XX_XXX_XXXX_XXXX-11-17-2014
    
    Delta:
    installc
    installd
    
    ===============================================================================
    DONE ...
    ===============================================================================
    
    
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. alicepattinson

    alicepattinson MDL Member

    Jan 29, 2013
    175
    32
    10
    I also need a guide what hypedave needs. I hope someone will help.
     
  15. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #75 s1ave77, Nov 19, 2014
    Last edited by a moderator: Apr 20, 2017
    Now i see the problem :doh:. Powershell is shortening the output to deltafile after 36 chars, will check for solution.

    Code:
    Exclusions:
    ABCDE_12345678_XXXX_XXX_XXXXX_XX_XXX_XXXX_0004-11-17-2014
    ABCDE_12345678_XXXX_XXX_XXXXX_XX_XXX_XXXX_0002-11-17-2014
    
    
    Folder:
    ABCDE_12345678_XXXX_XXX_XXXXX_XX_XXX_XXXX_0001-11-17-2014
    ABCDE_12345678_XXXX_XXX_XXXXX_XX_XXX_XXXX_0002-11-17-2014
    ABCDE_12345678_XXXX_XXX_XXXXX_XX_XXX_XXXX_0003-11-17-2014
    ABCDE_12345678_XXXX_XXX_XXXXX_XX_XXX_XXXX_0004-11-17-2014
    
    Delta:
    ABCDE_12345678_XXXX_XXX_XXXXX_XX_XXX...
    ABCDE_12345678_XXXX_XXX_XXXXX_XX_XXX...
    
    ===============================================================================
    DONE ...
    ===============================================================================
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  16. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    #76 hypedave, Nov 19, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    See told you I wasnt going crazy, Ha!

     
  17. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    Hi Alice, what might you require assistance with?

     
  18. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #78 s1ave77, Nov 19, 2014
    Last edited by a moderator: Apr 20, 2017
    Bitchy powershell :cool2:. Take this :p!!!!

    Needs to refine the output of powershell with Format-Table -AutoSize switch to avoid the cutting :nsa:.

    Change the old powershell for loop with this one:

    Code:
    for /f "tokens=1 delims= " %%a in ('"powershell Compare-Object -ReferenceObject (Get-Content %textfile%) -DifferenceObject (Get-Content %wimfile%) ^| Format-Table -AutoSize" ^| findstr /i "=^>"') do echo %%a>>%deltafile%

    Now output shows:

    Code:
    Exclusions:
    ABCDE_12345678_XXXX_XXX_XXXXX_XX_XXX_XXXX_0004-11-17-2014
    ABCDE_12345678_XXXX_XXX_XXXXX_XX_XXX_XXXX_0002-11-17-2014
    
    
    
    Folder:
    ABCDE_12345678_XXXX_XXX_XXXXX_XX_XXX_XXXX_0001-11-17-2014
    ABCDE_12345678_XXXX_XXX_XXXXX_XX_XXX_XXXX_0002-11-17-2014
    ABCDE_12345678_XXXX_XXX_XXXXX_XX_XXX_XXXX_0003-11-17-2014
    ABCDE_12345678_XXXX_XXX_XXXXX_XX_XXX_XXXX_0004-11-17-2014
    
    Delta:
    ABCDE_12345678_XXXX_XXX_XXXXX_XX_XXX_XXXX_0001-11-17-2014
    ABCDE_12345678_XXXX_XXX_XXXXX_XX_XXX_XXXX_0003-11-17-2014
    
    ===============================================================================
    DONE ...
    ===============================================================================
    
    

    EDIT: ================================

    Forgot to mention that '=>' canged to '=^>'.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  19. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    I started from fresh and receiving files now found DISM cant see e:\master\install.wim
    proceeds by not backing the WIM file and instead splits to e:\sources\install*.wim
     
  20. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    See my post above your's :D.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...