Hello everyone, I am in need of assistance. I have a folder of a random number of custom wim files. I need help with creating a powershell of bat script that will loop through a folder of wim's and merge multiple wim files to one wim. Can anyone assist?
It's my understanding that DISM does not support wildcards. This is what my script current looks likes; Code: Dism /ExportImage /SourceImageFile:Z:\Images\Project01.wim /SourceIndex:1 /DestinationImageFile:Z:\Images\install.wim Dism /ExportImage /SourceImageFile:Z:\Images\Project02.wim /SourceIndex:1 /DestinationImageFile:Z:\Images\install.wim Dism /ExportImage /SourceImageFile:Z:\Images\Project03.wim /SourceIndex:1 /DestinationImageFile:Z:\Images\install.wim Dism /ExportImage /SourceImageFile:Z:\Images\Project04.wim /SourceIndex:1 /DestinationImageFile:Z:\Images\install.wim The current problem is every time I add a new image I have to go back and edit the powershell script. Looking for a way to just automate this process.
Would use a for loop to get the WIM files ... : Code: for /r "Z:\Images" %%a in (*.wim) do ( Dism /ExportImage /SourceImageFile:%%a /SourceIndex:1 /DestinationImageFile:Z:\Images\install.wim )
Didn't notice that you export to install.wim in same folder, that could act unpredictable. Recommend to save to another folder.
I created a bat file with the following; Code: for /r "Z:\Images" %%a in (*.wim) do ( Dism /ExportImage /SourceImageFile:%%a /SourceIndex:1 /DestinationImageFile:Z:\Images\sources\install.wim I have received the following error code. Error: 87 The exportimage option is unknown. For more information, refer to the help by running DISM.exe /?.
Yeah, didn't notice the little error in your dism lines; should read: Code: for /r "Z:\Images" %%a in (*.wim) do ( Dism /Export-Image /SourceImageFile:%%a /SourceIndex:1 /DestinationImageFile:Z:\Images\sources\install.wim ) or use: Code: for /r "Z:\Images" %%a in (*.wim) do Dism /Export-Image /SourceImageFile:%%a /SourceIndex:1 /DestinationImageFile:Z:\Images\sources\install.wim
can do that with normal cmd prompt: Code: forfiles /m *.wim /s /c "cmd /c dism /export-image /sourceimagefile:"@FILE" /sourceindex:1 /destinationimagefile:newfile.wim"
I always underestimate forfiles command . Need to fight with it next. EDIT: Needs /p switch to set folder for WIMs: Code: forfiles /p "Z:\Images" /m *.wim /s /c "cmd /c dism /export-image /sourceimagefile:"@FILE" /sourceindex:1 /destinationimagefile:"Z:\install.wim" Code: F:\win\mount>forfiles /p "f:\win\mount" /m *.wim /s /c "cmd /c dism /export-imag e /sourceimagefile:"@FILE" /sourceindex:1 /destinationimagefile:f:\win\install.w im" Tool zur Imageverwaltung für die Bereitstellung Version: 6.3.9600.17031 Das Image wird exportiert. [==========================100.0%==========================] Der Vorgang wurde erfolgreich beendet. Tool zur Imageverwaltung für die Bereitstellung Version: 6.3.9600.17031 Das Image wird exportiert. [==========================100.0%==========================] Der Vorgang wurde erfolgreich beendet.
The following code worked for me Code: for /r "Z:\Images" %%a in (*.wim) do Dism /Export-Image /SourceImageFile:%%a /SourceIndex:1 /DestinationImageFile:Z:\Images\sources\install.wim Now I will focus on building out the rest of my script. 1 - Service WIM files with latest updates 2 - Automagically find and merge all wims files in a folder to a single wim file. 3 - Split newly created merged wim file to separate swm files Thanks everyone.
One folder contains Windows 7 and the other folder contains Windows 8.1. Now the clients wants me to create a MSI package of the final script. I need to learn more about the forfiles command.
Code: C:\Windows\system32>forfiles /? FORFILES [/P pathname] [/M searchmask] [/S] [/C command] [/D [+ | -] {dd.MM.yyyy | dd}] Description: Selects a file (or set of files) and executes a command on that file. This is helpful for batch jobs. Parameter List: /P pathname Indicates the path to start searching. The default folder is the current working directory (.). /M searchmask Searches files according to a searchmask. The default searchmask is '*' . /S Instructs forfiles to recurse into subdirectories. Like "DIR /S". /C command Indicates the command to execute for each file. Command strings should be wrapped in double quotes. The default command is "cmd /c echo @file". The following variables can be used in the command string: @file - returns the name of the file. @fname - returns the file name without extension. @ext - returns only the extension of the file. @path - returns the full path of the file. @relpath - returns the relative path of the file. @isdir - returns "TRUE" if a file type is a directory, and "FALSE" for files. @fsize - returns the size of the file in bytes. @fdate - returns the last modified date of the file. @ftime - returns the last modified time of the file. To include special characters in the command line, use the hexadecimal code for the character in 0xHH format (ex. 0x09 for tab). Internal CMD.exe commands should be preceded with "cmd /c". /D date Selects files with a last modified date greater than or equal to (+), or less than or equal to (-), the specified date using the "dd.MM.yyyy" format; or selects files with a last modified date greater than or equal to (+) the current date plus "dd" days, or less than or equal to (-) the current date minus "dd" days. A valid "dd" number of days can be any number in the range of 0 - 32768. "+" is taken as default sign if not specified. /? Displays this help message. Examples: FORFILES /? FORFILES FORFILES /P C:\WINDOWS /S /M DNS*.* FORFILES /S /M *.txt /C "cmd /c type @file | more" FORFILES /P C:\ /S /M *.bat FORFILES /D -30 /M *.exe /C "cmd /c echo @path 0x09 was changed 30 days ago" FORFILES /D 01.01.2001 /C "cmd /c echo @fname is new since Jan 1st 2001" FORFILES /D +12.11.2014 /C "cmd /c echo @fname is new today" FORFILES /M *.exe /D +1 FORFILES /S /M *.doc /C "cmd /c echo @fsize" FORFILES /M *.txt /C "cmd /c if @isdir==FALSE notepad.exe @file"
Do I have this right? The goal is to do the following; Loop through folder of wims mount the wim inject windows updates dismount move on to the next wim until complete. then merge wims to one file and then split. Here is my code. I deally I 'd prefer to mount the master wim with multiple indexes and inject the updates. Code: for /r "C:\images" %%a in (*.wim) do DISM /mount-wim /wimfile:C:\Extract\sources\%%a /mountdir:C:\mount /index: DISM /image:C:\images\mount /Add-Package /PackagePath:C:\images\wsusoffline\client\w63-x64\glb DISM /unmount-wim /mountdir:C:\images\mount /commit for /r "C:\images" %%a in (*.wim) do Dism /Export-Image /SourceImageFile:%%a /SourceIndex:1 /DestinationImageFile:C:\images\master\install.wim Dism /Split-Image /ImageFile:C:\images\master\install.wim /SWMFile:C:\images\sources\install.swm /FileSize:256
Would recommend to mount the single WIMS one by one and add updates in each pass: Code: for /r "C:\images" %%a in (*.wim) do ( 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 DISM /unmount-wim /mountdir:C:\images\mount /commit ) Then export all single WIMs to master WIM and split. Recommend to store master WIM in another folder to avoid problems in the loop. Code: for /r "C:\images" %%a in (*.wim) do Dism /Export-Image /SourceImageFile:%%a /SourceIndex:1 /DestinationImageFile:C:\master\install.wim /compress:max /CheckIntegrity Dism /Split-Image /ImageFile:C:\images\master\install.wim /SWMFile:C:\images\sources\install.swm /FileSize:256 Would go for a bigger size of SWMs: 4000.
Okay what if I want to do the following; 1. Backup Wim 2. Mount it and save as new file name. I've noticed that imaging is quacking when using smaller swm files. What's the concern over a file 4GB vs a file of 500mb? Thanks for all your help so far.
#1. I mostly apply WIM/ESD/SWM via DISM from Win PE to avoid several Setup errors/traps (especially with splitted files). #2. OK. You want to export all WIMs to one master WIM, backup that one and then work with a copy, correct? Mount is limitted here, you can only mount a WIM and then unmount/commit to the same WIM. To change the names you need to export it.