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
    129
    30
    10
    #101 hypedave, Nov 20, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Pickup where we left off. It's not running the Windows Updates. It errors out DISM is looking for a e:\wim\A.wim

    Code:
    DISM   DISM.EXE: Executing command line: Dism  /Export-Image /SourceImageFile:e:\wim\At.wim /SourceIndex:1 /DestinationImageFile:e:\backup\backup_11-20-2014-00-45.wim /compress:max /CheckIntegrity
     
  2. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #102 s1ave77, Nov 20, 2014
    Last edited by a moderator: Apr 20, 2017
    That happens when the compare for loop parses powershell error output. See:

    Code:
    PS C:\Users\s1ave77\Desktop> Compare-Object -ReferenceObject (Get-Content f:\win\wim\exclusions.txt) -DifferenceObject (
    Get-Content f:\win\wim\wimlist.txt) | where-object SideIndicator -eq "=>" | select -ExpandProperty InputObject | f
    f : Die Benennung "f" wurde nicht als Name eines Cmdlet, einer Funktion, einer Skriptdatei oder eines ausführbaren
    Programms erkannt. Überprüfen Sie die Schreibweise des Namens, oder ob der Pfad korrekt ist (sofern enthalten), und
    wiederholen Sie den Vorgang.
    In Zeile:1 Zeichen:205
    + ...  InputObject | f
    +                    ~
        + CategoryInfo          : ObjectNotFound: (f:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
    
    
    In english it would be At Line:1 Char:205, so it sets 'At' as value ('In' for my german system).


    Summary: Must be a problem when comparing WIM folders file names with the ones from exclusion text.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #103 s1ave77, Nov 20, 2014
    Last edited by a moderator: Apr 20, 2017
    Noticed there slipped in a space in that for loop.

    Instead of:
    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%
    it must be:
    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%

    Yeah, with that space in "= ^>" i also get that error:

    Code:
    C:\Windows\system32>for /f "tokens=1 delims= " %a in ('"powershell Compare-Objec
    t -ReferenceObject (Get-Content f:\win\wim\exclusions.txt) -DifferenceObject (Ge
    t-Content f:\win\wim\wimlist.txt) ^| Format-Table -AutoSize" ^| findstr /i "= ^>
    "') do echo %a
    
    C:\Windows\system32>echo In
    In
    
    C:\Windows\system32>echo +
    +
    
    C:\Windows\system32>echo +
    +
    
    C:\Windows\system32>echo Dateispezifikation
    Dateispezifikation
    
    C:\Windows\system32>echo +
    +
    
    C:\Windows\system32>echo ception
    ception
    
    C:\Windows\system32>echo +
    +
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    Ok so here is what's happening. It completed the task to Backup up to f:\backup\backup_%timestamp%.wim with no issues. Now it's not executing the next step to mount the wim and begin injecting packages.
     
  5. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    Can't see a problem ... post your current code to check.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    #106 hypedave, Nov 21, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    here ya go
    I think it may be the way DISM is being called to mount the image

    Code:
    gtr 0 DISM /image:e:\mount /Add-Package /PackagePath:%updates5%\Baseline
    Code:
    gtr 0DISM /Mount-image /ImageFile:e:\mount /Add-Package /PackagePath:%updates5%\Baseline
    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%
    :: Exclude WIms from 
    set textfile=f:\wim\exclusions.txt
    :: Path to update packages group 1
    set updates1=f:\updates\Windows7-x64
    :: Path to update packages group 2
    set updates2=f:\updates\Windows7-x86
    :: Path to update packages group 3
    set updates3=f:\updates\Windows8-x64
    :: Path to update packages group 4
    set updates4=f:\updates\Windows8-x86
    :: Path to update packages group 5
    set updates5=f:\updates\Windows8.1-x64
    :: Path to update packages group 6
    set updates6=f:\updates\Windows8.1-x86
    :: set compare files
    set "wimfile=f:\wim\wimlist.txt"
    set "deltafile=f:\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:\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%) ^| Format-Table -AutoSize" ^| 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=f:\files
    set target=f:\mount
    
    :: start procedure
    :: backup all WIMs to f:\backup\backup.wim
    echo.
    echo ===============================================================================
    echo Backing up to f:\backup\backup_%timestamp%.wim
    echo ===============================================================================
    echo.
    set "p=0"
    for /f "tokens=* delims= " %%a in (%deltafile%) do (
    echo Exporting %%a to f:\backup\backup.wim
    echo.
    Dism /Export-Image /SourceImageFile:f:\wim\%%a.wim /SourceIndex:1 /DestinationImageFile:f:\backup\backup_%timestamp%.wim /compress:max /CheckIntegrity
    )
    :: mount single WIMs to f:\mount, add updates and unmount/commit
    echo.
    echo ===============================================================================
    echo Mounting to f:\mount
    echo Adding Updates
    echo Unmount/Commit
    echo ===============================================================================
    echo.
    :: execute loop for deltas only
    for /f "tokens=* delims= " %%a in (%deltafile%) do (
    echo Processing %%a
    echo.
    DISM /mount-wim /wimfile:f:\wim\%%a.wim /index:1 /mountdir:f:\mount
    echo %%a | find "w7sp1x64" 1>nul && (
    set "a=0"&&set "b=0"&&set "c=0"&&set "d=0"&&set "e=0"&&set "f=0"
    for /r "%updates1%\Baseline" %%a in (*.*) do set /a a+=1
    for /r "%updates1%\General%" %%a in (*.*) do set /a b+=1
    for /r "%updates1%\Hotfix" %%a in (*.*) do set /a c+=1
    for /r "%updates1%\Security" %%a in (*.*) do set /a d+=1
    for /r "%updates1%\Additional" %%a in (*.*) do set /a e+=1
    for /r "%updates1%\Extra" %%a in (*.*) do set /a f+=1
    if /i !a! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates1%\Baseline
    if /i !b! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates1%\General
    if /i !c! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates1%\Hotfix
    if /i !d! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates1%\Security
    if /i !e! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates1%\Additional
    if /i !f! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates1%\Extra
    )
    echo %%a | find "w7sp1x86" 1>nul && (
    set "a=0"&&set "b=0"&&set "c=0"&&set "d=0"&&set "e=0"&&set "f=0"
    for /r "%updates2%\Baseline" %%a in (*.*) do set /a a+=1
    for /r "%updates2%\General%" %%a in (*.*) do set /a b+=1
    for /r "%updates2%\Hotfix" %%a in (*.*) do set /a c+=1
    for /r "%updates2%\Security" %%a in (*.*) do set /a d+=1
    for /r "%updates2%\Additional" %%a in (*.*) do set /a e+=1
    for /r "%updates2%\Extra" %%a in (*.*) do set /a f+=1
    if /i !a! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates2%\Baseline
    if /i !b! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates2%\General
    if /i !c! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates2%\Hotfix
    if /i !d! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates2%\Security
    if /i !e! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates2%\Additional
    if /i !f! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates2%\Extra
    )
    echo %%a | find "w8x64" 1>nul && (
    set "a=0"&&set "b=0"&&set "c=0"&&set "d=0"&&set "e=0"&&set "f=0"
    for /r "%updates3%\Baseline" %%a in (*.*) do set /a a+=1
    for /r "%updates3%\General%" %%a in (*.*) do set /a b+=1
    for /r "%updates3%\Hotfix" %%a in (*.*) do set /a c+=1
    for /r "%updates3%\Security" %%a in (*.*) do set /a d+=1
    for /r "%updates3%\Additional" %%a in (*.*) do set /a e+=1
    for /r "%updates3%\Extra" %%a in (*.*) do set /a f+=1
    if /i !a! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates3%\Baseline
    if /i !b! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates3%\General
    if /i !c! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates3%\Hotfix
    if /i !d! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates3%\Security
    if /i !e! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates3%\Additional
    if /i !f! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates3%\Extra
    )
    echo %%a | find "w8x86" 1>nul && (
    set "a=0"&&set "b=0"&&set "c=0"&&set "d=0"&&set "e=0"&&set "f=0"
    for /r "%updates4%\Baseline" %%a in (*.*) do set /a a+=1
    for /r "%updates4%\General%" %%a in (*.*) do set /a b+=1
    for /r "%updates4%\Hotfix" %%a in (*.*) do set /a c+=1
    for /r "%updates4%\Security" %%a in (*.*) do set /a d+=1
    for /r "%updates4%\Additional" %%a in (*.*) do set /a e+=1
    for /r "%updates4%\Extra" %%a in (*.*) do set /a f+=1
    if /i !a! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates4%\Baseline
    if /i !b! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates4%\General
    if /i !c! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates4%\Hotfix
    if /i !d! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates4%\Security
    if /i !e! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates4%\Additional
    if /i !f! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates4%\Extra
    )
    echo %%a | find "w81u1x64" 1>nul && (
    set "a=0"&&set "b=0"&&set "c=0"&&set "d=0"&&set "e=0"&&set "f=0"
    for /r "%updates5%\Baseline" %%a in (*.*) do set /a a+=1
    for /r "%updates5%\General%" %%a in (*.*) do set /a b+=1
    for /r "%updates5%\Hotfix" %%a in (*.*) do set /a c+=1
    for /r "%updates5%\Security" %%a in (*.*) do set /a d+=1
    for /r "%updates5%\Additional" %%a in (*.*) do set /a e+=1
    for /r "%updates5%\Extra" %%a in (*.*) do set /a f+=1
    if /i !a! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates5%\Baseline
    if /i !b! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates5%\General
    if /i !c! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates5%\Hotfix
    if /i !d! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates5%\Security
    if /i !e! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates5%\Additional
    if /i !f! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates5%\Extra
    )
    echo %%a | find "w81u1x86" 1>nul && (
    set "a=0"&&set "b=0"&&set "c=0"&&set "d=0"&&set "e=0"&&set "f=0"
    for /r "%updates6%\Baseline" %%a in (*.*) do set /a a+=1
    for /r "%updates6%\General%" %%a in (*.*) do set /a b+=1
    for /r "%updates6%\Hotfix" %%a in (*.*) do set /a c+=1
    for /r "%updates6%\Security" %%a in (*.*) do set /a d+=1
    for /r "%updates6%\Additional" %%a in (*.*) do set /a e+=1
    for /r "%updates6%\Extra" %%a in (*.*) do set /a f+=1
    if /i !a! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates6%\Baseline
    if /i !b! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates6%\General
    if /i !c! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates6%\Hotfix
    if /i !d! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates6%\Security
    if /i !e! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates6%\Additional
    if /i !f! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates6%\Extra
    )
    xcopy.exe %path1%\*.* %target%\*.* /s /d /e /h /r /k /y
    DISM /unmount-wim /mountdir:f:\mount /commit
    echo %%a>>%textfile%
    )
    :: merge single WIMs to f:\master\install.wim
    echo.
    echo ===============================================================================
    echo Exporting to f:\master
    echo ===============================================================================
    echo.
    for /f "tokens=* delims= " %%a in (%deltafile%) do (
    echo Exporting %%a to f:\master\install.wim
    echo.
    Dism /Export-Image /SourceImageFile:f:\wim\%%a.wim /SourceIndex:1 /DestinationImageFile:f:\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 f:\sources
    echo ===============================================================================
    echo.
    Dism /Split-Image /ImageFile:f:\master\install.wim /SWMFile:f:\sources\install.swm /FileSize:256
    
    :: end procedure
    :: script will pause here
    echo.
    echo ===============================================================================
    echo DONE ...
    echo ===============================================================================
    echo.
    pause
    
    :: EXIT
    endlocal
    exit
    
     
  7. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #107 s1ave77, Nov 21, 2014
    Last edited by a moderator: Apr 20, 2017
    Does it at least show:

    Code:
    echo.
    echo ===============================================================================
    echo Mounting to f:\mount
    echo Adding Updates
    echo Unmount/Commit
    echo ===============================================================================
    echo.
    
    Or stops before :g:?

    Is the mount folder accessible.

    Code still looks legit. The process itself gives noe errors here.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    #108 hypedave, Nov 21, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Nope it closes instantly after the image is backed up. The mount folder is accessible to.

     
  9. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    #109 hypedave, Nov 21, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Could it be this spot highlighted in red

    Code:
    echo ===============================================================================
    echo Mounting to e:\mount
    echo Adding Updates
    echo Unmount/Commit
    echo ===============================================================================
    echo.
    :: execute loop for deltas only
    for /f "tokens=* delims= " %%a in (%deltafile%) do ( 
    echo Processing %%a
     
  10. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #110 s1ave77, Nov 21, 2014
    Last edited by a moderator: Apr 20, 2017
    Nope, was able to find to flaw, was a bit hidden this time, a simple copy and paste issue. Instead of:

    Code:
    for /r "%updates3%\General%" %%a in (*.*) do set /a b+=1
    Must be:

    Code:
    for /r "%updates3%\General" %%a in (*.*) do set /a b+=1
    With that % it's considered as undefined variable and causes the loop to break instantly, tested with pause command before it, but still breaks instantly.

    Corrected Code (only success messages accepted):

    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%
    :: Exclude WIms from 
    set textfile=f:\wim\exclusions.txt
    :: Path to update packages group 1
    set updates1=f:\updates\Windows7-x64
    :: Path to update packages group 2
    set updates2=f:\updates\Windows7-x86
    :: Path to update packages group 3
    set updates3=f:\updates\Windows8-x64
    :: Path to update packages group 4
    set updates4=f:\updates\Windows8-x86
    :: Path to update packages group 5
    set updates5=f:\updates\Windows8.1-x64
    :: Path to update packages group 6
    set updates6=f:\updates\Windows8.1-x86
    :: set compare files
    set "wimfile=f:\wim\wimlist.txt"
    set "deltafile=f:\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:\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%) ^| Format-Table -AutoSize" ^| 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=f:\files
    set target=f:\mount
    
    :: start procedure
    :: backup all WIMs to f:\backup\backup.wim
    echo.
    echo ===============================================================================
    echo Backing up to f:\backup\backup_%timestamp%.wim
    echo ===============================================================================
    echo.
    set "p=0"
    for /f "tokens=* delims= " %%a in (%deltafile%) do (
    echo Exporting %%a to f:\backup\backup.wim
    echo.
    Dism /Export-Image /SourceImageFile:f:\wim\%%a.wim /SourceIndex:1 /DestinationImageFile:f:\backup\backup_%timestamp%.wim /compress:max /CheckIntegrity
    )
    :: mount single WIMs to f:\mount, add updates and unmount/commit
    echo.
    echo ===============================================================================
    echo Mounting to f:\mount
    echo Adding Updates
    echo Unmount/Commit
    echo ===============================================================================
    echo.
    :: execute loop for deltas only
    for /f "tokens=* delims= " %%a in (%deltafile%) do (
    echo Processing %%a
    echo.
    DISM /mount-wim /wimfile:f:\wim\%%a.wim /index:1 /mountdir:f:\mount
    echo %%a | find "w7sp1x64" 1>nul && (
    set "a=0"&&set "b=0"&&set "c=0"&&set "d=0"&&set "e=0"&&set "f=0"
    for /r "%updates1%\Baseline" %%a in (*.*) do set /a a+=1
    for /r "%updates1%\General" %%a in (*.*) do set /a b+=1
    for /r "%updates1%\Hotfix" %%a in (*.*) do set /a c+=1
    for /r "%updates1%\Security" %%a in (*.*) do set /a d+=1
    for /r "%updates1%\Additional" %%a in (*.*) do set /a e+=1
    for /r "%updates1%\Extra" %%a in (*.*) do set /a f+=1
    if /i !a! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates1%\Baseline
    if /i !b! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates1%\General
    if /i !c! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates1%\Hotfix
    if /i !d! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates1%\Security
    if /i !e! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates1%\Additional
    if /i !f! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates1%\Extra
    )
    echo %%a | find "w7sp1x86" 1>nul && (
    set "a=0"&&set "b=0"&&set "c=0"&&set "d=0"&&set "e=0"&&set "f=0"
    for /r "%updates2%\Baseline" %%a in (*.*) do set /a a+=1
    for /r "%updates2%\General" %%a in (*.*) do set /a b+=1
    for /r "%updates2%\Hotfix" %%a in (*.*) do set /a c+=1
    for /r "%updates2%\Security" %%a in (*.*) do set /a d+=1
    for /r "%updates2%\Additional" %%a in (*.*) do set /a e+=1
    for /r "%updates2%\Extra" %%a in (*.*) do set /a f+=1
    if /i !a! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates2%\Baseline
    if /i !b! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates2%\General
    if /i !c! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates2%\Hotfix
    if /i !d! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates2%\Security
    if /i !e! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates2%\Additional
    if /i !f! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates2%\Extra
    )
    echo %%a | find "w8x64" 1>nul && (
    set "a=0"&&set "b=0"&&set "c=0"&&set "d=0"&&set "e=0"&&set "f=0"
    for /r "%updates3%\Baseline" %%a in (*.*) do set /a a+=1
    for /r "%updates3%\General" %%a in (*.*) do set /a b+=1
    for /r "%updates3%\Hotfix" %%a in (*.*) do set /a c+=1
    for /r "%updates3%\Security" %%a in (*.*) do set /a d+=1
    for /r "%updates3%\Additional" %%a in (*.*) do set /a e+=1
    for /r "%updates3%\Extra" %%a in (*.*) do set /a f+=1
    if /i !a! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates3%\Baseline
    if /i !b! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates3%\General
    if /i !c! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates3%\Hotfix
    if /i !d! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates3%\Security
    if /i !e! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates3%\Additional
    if /i !f! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates3%\Extra
    )
    echo %%a | find "w8x86" 1>nul && (
    set "a=0"&&set "b=0"&&set "c=0"&&set "d=0"&&set "e=0"&&set "f=0"
    for /r "%updates4%\Baseline" %%a in (*.*) do set /a a+=1
    for /r "%updates4%\General" %%a in (*.*) do set /a b+=1
    for /r "%updates4%\Hotfix" %%a in (*.*) do set /a c+=1
    for /r "%updates4%\Security" %%a in (*.*) do set /a d+=1
    for /r "%updates4%\Additional" %%a in (*.*) do set /a e+=1
    for /r "%updates4%\Extra" %%a in (*.*) do set /a f+=1
    if /i !a! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates4%\Baseline
    if /i !b! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates4%\General
    if /i !c! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates4%\Hotfix
    if /i !d! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates4%\Security
    if /i !e! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates4%\Additional
    if /i !f! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates4%\Extra
    )
    echo %%a | find "w81u1x64" 1>nul && (
    set "a=0"&&set "b=0"&&set "c=0"&&set "d=0"&&set "e=0"&&set "f=0"
    for /r "%updates5%\Baseline" %%a in (*.*) do set /a a+=1
    for /r "%updates5%\General" %%a in (*.*) do set /a b+=1
    for /r "%updates5%\Hotfix" %%a in (*.*) do set /a c+=1
    for /r "%updates5%\Security" %%a in (*.*) do set /a d+=1
    for /r "%updates5%\Additional" %%a in (*.*) do set /a e+=1
    for /r "%updates5%\Extra" %%a in (*.*) do set /a f+=1
    if /i !a! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates5%\Baseline
    if /i !b! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates5%\General
    if /i !c! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates5%\Hotfix
    if /i !d! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates5%\Security
    if /i !e! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates5%\Additional
    if /i !f! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates5%\Extra
    )
    echo %%a | find "w81u1x86" 1>nul && (
    set "a=0"&&set "b=0"&&set "c=0"&&set "d=0"&&set "e=0"&&set "f=0"
    for /r "%updates6%\Baseline" %%a in (*.*) do set /a a+=1
    for /r "%updates6%\General" %%a in (*.*) do set /a b+=1
    for /r "%updates6%\Hotfix" %%a in (*.*) do set /a c+=1
    for /r "%updates6%\Security" %%a in (*.*) do set /a d+=1
    for /r "%updates6%\Additional" %%a in (*.*) do set /a e+=1
    for /r "%updates6%\Extra" %%a in (*.*) do set /a f+=1
    if /i !a! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates6%\Baseline
    if /i !b! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates6%\General
    if /i !c! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates6%\Hotfix
    if /i !d! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates6%\Security
    if /i !e! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates6%\Additional
    if /i !f! gtr 0 DISM /image:f:\mount /Add-Package /PackagePath:%updates6%\Extra
    )
    xcopy.exe %path1%\*.* %target%\*.* /s /d /e /h /r /k /y
    DISM /unmount-wim /mountdir:f:\mount /commit
    echo %%a>>%textfile%
    )
    :: merge single WIMs to f:\master\install.wim
    echo.
    echo ===============================================================================
    echo Exporting to f:\master
    echo ===============================================================================
    echo.
    for /f "tokens=* delims= " %%a in (%deltafile%) do (
    echo Exporting %%a to f:\master\install.wim
    echo.
    Dism /Export-Image /SourceImageFile:f:\wim\%%a.wim /SourceIndex:1 /DestinationImageFile:f:\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 f:\sources
    echo ===============================================================================
    echo.
    Dism /Split-Image /ImageFile:f:\master\install.wim /SWMFile:f:\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...
  11. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    And ... any better news to submit :nsa:?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    It's rocking along so far. I have it processing 20 wim files. My last task is to have it inject drivers using the same concept as applying packages. All the drivers will be in an organized folder based upon "OS\Make\Model".
     
  13. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    If it's possible to determine from the WIM name, the same find constructs can be used.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    Yes that is correct. WIM file will contain the following Make_Manufactuer

    This is an idea of what the folder structure looks like.

    E:\drivers\Windows 7 x64\Manufactuer\Model
    E:\drivers\Windows 7 x86\Manufactuer\Model
    E:\drivers\Windows 8 x64\Manufactuer\Model
    E:\drivers\Windows 8 x86\Manufactuer\Model
    E:\drivers\Windows 8.1 x64\Manufactuer\Model
    E:\drivers\Windows 8.1 x86\Manufactuer\Model

    Using DISM command

    Dism /Image:C:\test\offline /Add-Driver /Driver:c:\drivers /Recurse/ForceUnsigned

    after the package command before xcopy.exe
     
  15. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #115 s1ave77, Nov 21, 2014
    Last edited by a moderator: Apr 20, 2017
    Not sure if i have enough time tomorrow, will see. Assuming there is always at least one driver, it would supersede the checks and shorten it a bit.

    Create a list with all Possible variations and set the general pathes to each main driver folder:

    Code:
    set "driversw7x64=E:\drivers\Windows 7 x64"
    NOTE: The quotes are a must in case a path with spaces is used else DISM will error.

    Code:
    echo %%a | find "w7sp1x64_XXXXXXXX" 1>nul && Dism /Image:"F:\mount" /Add-Driver /Driver:"%driversw7x64%\Acer\Model_XX" /Recurse /ForceUnsigned
    
    
    For that reason i always use quotes, to avoid trouble :cool2:.

    NOTE 2: In your code is no space between /recurse and /forceunsigned (works with small switches likewise).
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  16. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    Please tell me you dont need all the various makes and model :eek:

    The main make and model folder would like this

    C:\driverpack\Windows 8.1 x64\Dell Inc\Latitude 3340

    Now if you want the additional folders within there then its a hit a miss but here ya go
    (The /Recurse switch scan all sub folders)

    C:\driverpack\Windows 8.1 x64\Dell Inc\Latitude 3340\audio
    C:\driverpack\Windows 8.1 x64\Dell Inc\Latitude 3340\chipset
    C:\driverpack\Windows 8.1 x64\Dell Inc\Latitude 3340\communication
    C:\driverpack\Windows 8.1 x64\Dell Inc\Latitude 3340\input
    C:\driverpack\Windows 8.1 x64\Dell Inc\Latitude 3340\network
    C:\driverpack\Windows 8.1 x64\Dell Inc\Latitude 3340\storage
    C:\driverpack\Windows 8.1 x64\Dell Inc\Latitude 3340\video


    Yeah dont worry about the spaces in the sample code. That was just an example really.
     
  17. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #117 s1ave77, Nov 21, 2014
    Last edited: Nov 21, 2014
    OOOOOK ... copy that. How would the string in the WIM name look in that case. Best would be to have it next to the 'w7sp1x64' one.

    And yes, it needs to define all variations in that case :cool2:.

    BTW: If you have it once done, it's pretty easy to add more.


    HINT: In case you use Windows Notepad i'd recommend to switch to Notepad++ (Syntax highlighting, Tabs, double entries with Strg+D and more) :good3:.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  18. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10

    Example file name

    Project_Customer_w81u1x64_Make_Model_11-10-2014
    Project_Customer_w81u1x64_Dell_Latitude_3340_11-10-2014

    I use notepad++ all the time can we just try with the top level folder

    "C:\driverpack\Windows 8.1 x64\Dell Inc\Latitude 3340"

    Having each additional subdirectory is going to get nasty and will vary from makes and models.
     
  19. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    That would be the main directory. Recurse switch will check any sub-folder beneath.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  20. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #120 s1ave77, Nov 21, 2014
    Last edited by a moderator: Apr 20, 2017
    Examples for driver integration.

    Needs set commands for each Windows version:
    Code:
    set "driversw7x64=E:\drivers\Windows 7 x64"
    set "driversw8.1x64=E:\drivers\Windows 8.1 x64"
    
    I would sort them by Win version and then Vendor and Model:
    Code:
    echo %%a | find "w7sp1x64_Dell_Latitude_3340" 1>nul && Dism /Image:"F:\mount" /Add-Driver /Driver:"%driversw7x64%\Dell\Latitude 3340" /Recurse /ForceUnsigned
    echo %%a | find "w7sp1x64_Dell_Latitude_3XXX" 1>nul && Dism /Image:"F:\mount" /Add-Driver /Driver:"%driversw7x64%\Dell\Latitude 3XXX" /Recurse /ForceUnsigned
    echo %%a | find "w7sp1x64_Dell_Latitude_3XXX" 1>nul && Dism /Image:"F:\mount" /Add-Driver /Driver:"%driversw7x64%\Dell\Latitude 3XXX" /Recurse /ForceUnsigned
    ::-----------------------------------------------------------------------------------------------------------------------------------------------------------------
    echo %%a | find "w81u1x64_Dell_Latitude_3340" 1>nul && Dism /Image:"F:\mount" /Add-Driver /Driver:"%driversw8.1x64%\Dell\Latitude 3340" /Recurse /ForceUnsigned
    echo %%a | find "w81u1x64_Dell_Latitude_3340" 1>nul && Dism /Image:"F:\mount" /Add-Driver /Driver:"%driversw8.1x64%\Dell\Latitude 3340" /Recurse /ForceUnsigned
    echo %%a | find "w81u1x64_Dell_Latitude_3340" 1>nul && Dism /Image:"F:\mount" /Add-Driver /Driver:"%driversw8.1x64%\Dell\Latitude 3340" /Recurse /ForceUnsigned
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...