Was exprimenting a lot with them the last time, as they are very handy to automate processes (i.e. add packages in install order given in a txt file for each found index). Partially they are still a mystery for me .
Lets say for instance that we were reading the same information from a file instead of a piped command. How do you think it could be improved by using SET commands and such? I'm just trying to wrap my mind about the limitations of the variables here... BTW your avatar still looks like a dog who farted or something
Depends on the text file content that should be parsed. Not sure what you want to achieve . Using that to get install order from txt file Code: set path5=J:\win\mount set path10=J:\Update\order.txt for /F "tokens=*" %%G in (%path10%) do ( Dism /Image:"%path5%" /Add-Package /PackagePath:"%temp%\CAB\%%G.cab" ) order.txt looks like this: Code: windows8.1-kb2919442-x64 windows8.1-kb2939087-x64 windows8.1-kb2919355-x64 windows8.1-kb2932046-x64 windows8.1-kb2937592-x64 windows8.1-kb2938439-x64 BTW: Was love at first sight with my avatar . And looks a bit like two of my dogs did.
Although the second loop works when using with in the first loop but when using only the second loop and specifying the index no it doesn't work Code: for /f "tokens=2 delims=: " %%a in ('DISM /Get-WimInfo /WimFile:"%path2%" ^| findstr /i Index') do ( for /f "tokens=2 delims=: " %%g in ('DISM /Get-WimInfo /WimFile:"%path2%" /Index:%%a ^| findstr /i Name') do ( echo %%a.%%g ) ) So here is my problem, having a space at the start of the WIM Index Name is not a problem when it's just used for displaying.. we can adjust the space with the echo command. but when I need to assign the WIM Index Name to a variable for future use like where I need to assign the index name to a new wim then it will be problem. so here is the code and output of several trials Code: @echo off set InstallWim=%~dp0DVD\sources\install.esd cls echo. for /f "tokens=2 delims=:" %%a in ('DISM /Get-WimInfo /WimFile:%InstallWim% /Index:4 ^| findstr /i Name') do (echo ---%%a---) for /f "tokens=2 delims=: " %%b in ('DISM /Get-WimInfo /WimFile:%InstallWim% /Index:4 ^| findstr /i Name') do (echo ---%%b---) for /f "tokens=2,* delims=: " %%c in ('DISM /Get-WimInfo /WimFile:%InstallWim% /Index:4 ^| findstr /i Name') do (echo ---%%c---) for /f "tokens=2,* delims=:" %%d in ('DISM /Get-WimInfo /WimFile:%InstallWim% /Index:4 ^| findstr /i Name') do (echo ---%%d---) for /f "tokens=2 delims=:, " %%e in ('DISM /Get-WimInfo /WimFile:%InstallWim% /Index:4 ^| findstr /i Name') do (echo ---%%e---) for /f "tokens=2,* delims=:, " %%f in ('DISM /Get-WimInfo /WimFile:%InstallWim% /Index:4 ^| findstr /i Name') do (echo ---%%f---) echo. pause exit Output : Code: --- Windows 8.1 Pro WMC--- ---Windows--- ---Windows--- --- Windows 8.1 Pro WMC--- ---Windows--- ---Windows--- Press any key to continue . . .
Don't know man I'm not much of a unattend guy. Please mask your key tho... Edit: no wonder I didn't recognize it... use a gVLK instead of the retail key for KMS activation bud.
Please explain how you have done pre-activation in "Windows 8.1 AIO S14 x86 en-US DaRT 8.1 Pre-Activated Mar2014"?
Export non-activated index to new install.wim Remount the non-activated index, copy over different $oem$ files set gVLK with dism unmount rename index with imagex export pre-activated index to other install.wim
I think I worked out a method of incorporating powershell storage cmdlets into my little diskpart apply project It's actually very much the same way that diskpart handles it, except that I have to script all of the diskpart actions. The good news is that because I don't have to deal with tons of diskpart scripts or running out of ram because of a piping error, I can use a few variable choices and make the setup much more customizable Although you could probably script the entire thing in powershell, I find that cmd scripts are easier to work with while passing commands to powershell such as: powershell get-disk The benefit should be obvious if you've ever worked with diskpart scripts. I have a few plans for working on this project in the short-term: 1) Get it working for a single-OS install with powershell commands replacing diskpart 2) Allow offline integration of drivers after applying image to partition (Raid fails on win7/server2008r2 anyone?) 3) Allow multi-boot and deal with bcdboot for the different windows versions That should keep me busy for a while. I'm sure I'll have a hard time parsing things and need help from time to time.
Yeah, tricky thing here. Easiest way would be to use the double loop and write the Names to a temp text file and parse them from that to get it set to variables . @ murphy78 Really nice avatar . Already laughed my a** off ... .
There's a commercial that goes on television around here for some dog dental sticks or something and it does a little gimmick about doggie dentures... that's one of the pictures.
Well crap. Powershell works but it's a PITA to integrate into the boot.wim because of the like 10 cabs you have to add, plus it's slow as hell and less functional than diskpart In diskpart you can clean disk and it doesn't give a sh** if it's already clean. In powershell you have to tell it to ignore errors when clear-disk'ing diskpart imports naturally don't nag you with confirmation requests again in powershell you have to specify -confirm:$false It has weird rules about not accepting certain arguments when you use partition settings vs volume settings as well. It's really a damn nightmare to properly learn these commands as they are not intuitive at all. If that wasn't annoying enough, they are slow as hell. There seems to be a long initialization time between starting each command and actually running each command's function. I have no idea how to describe it. It's like taking each diskpart command and tacking on an extra 10-20 seconds each. As much as I like the idea of having a future-proof powershell version of this disk stuff. I am pretty sure that diskpart import will be around at least until this type of installation becomes obsolete. So sadly, I believe I'm going to try flipp3r's idea and do echo commands to create a diskpart script in the ramdrive during boot and import/delete that. I think there also might be an issue with running bcdboot with x64 images on x86 installs or something. I'll have to nail down the diskpart echo import stuff before I re-test that stuff. It could have been a problem with using powershell stuff. I learned a lot in the last few hours; mostly, what not to do. Still an important part of the process. I'll leave up a sample powershell portion of my script for reference here in case anyone wants to play with it: Code: IF %UEFI% EQU 1 ( :Clear and Initialize powershell clear-disk -number %DISK% -removedata -removeoem -Confirm:$false -ErrorAction:Ignore powershell initialize-disk -number %DISK% -partitionstyle GPT -Confirm:$false :Recovery Partition powershell new-partition -disknumber %DISK% -gpttype de94bba4-06d1-4d40-a16a-bfd50179d6ac -size 300MB -driveletter T powershell set-partition -disknumber %DISK% -partitionnumber 1 -nodefaultdriveletter:$true powershell format-volume -driveletter T -filesystem NTFS -Confirm:$false :EFI system Partition powershell new-partition -disknumber %DISK% -gpttype c12a7328-f81f-11d2-ba4b-00a0c93ec93b -size 100MB -driveletter S powershell set-partition -disknumber %DISK% -partitionnumber 2 -nodefaultdriveletter:$true powershell format-volume -driveletter S -filesystem FAT32 -Confirm:$false :MSR Microsoft Reserved Partition powershell new-partition -disknumber %DISK% -gpttype de94bba4-06d1-4d40-a16a-bfd50179d6ac -size 128MB powershell set-partition -disknumber %DISK% -partitionnumber 3 -nodefaultdriveletter:$true :Main disk Partition powershell new-partition -disknumber %DISK% -usemaximumsize -driveletter W powershell format-volume -driveletter W -filesystem NTFS -Confirm:$false ) IF %UEFI% EQU 0 ( :Clear and Initialize powershell clear-disk -number %DISK% -removedata -removeoem -Confirm:$false -ErrorAction:Ignore powershell initialize-disk -number %DISK% -partitionstyle MBR -Confirm:$false :System Partition powershell new-partition -disknumber %DISK% -size 350MB -driveletter S powershell set-partition -disknumber %DISK% -partitionnumber 1 -isactive:$true -nodefaultdriveletter:$true powershell format-volume -driveletter S -filesystem NTFS -Confirm:$false :Windows Partition powershell new-partition -disknumber %DISK% -usemaximumsize -driveletter W powershell format-volume -driveletter W -filesystem NTFS -Confirm:$false ) Note that I didn't test the UEFI version as even the MBR partitioned legacy booting version was so slow and not worth the effort and the chm instructions for adding powershell support, but notice the different path and edit if you plan to incorporate: Spoiler Code: Dism /Mount-Image /ImageFile:"C:\WinPE_amd64_PS\media\sources\boot.wim" /Index:1 /MountDir:"C:\WinPE_amd64_PS\mount" Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files\Windows Kits\8.1\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-WMI.cab" Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files\Windows Kits\8.1\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-WMI_en-us.cab" Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files\Windows Kits\8.1\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-NetFX.cab" Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files\Windows Kits\8.1\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-NetFX_en-us.cab" Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files\Windows Kits\8.1\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-Scripting.cab" Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files\Windows Kits\8.1\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-Scripting_en-us.cab" Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files\Windows Kits\8.1\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-PowerShell.cab" Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files\Windows Kits\8.1\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-PowerShell_en-us.cab" Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files\Windows Kits\8.1\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-StorageWMI.cab" Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files\Windows Kits\8.1\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-StorageWMI_en-us.cab" Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files\Windows Kits\8.1\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-DismCmdlets.cab" Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files\Windows Kits\8.1\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-DismCmdlets_en-us.cab" Dism /Unmount-Image /MountDir:C:\WinPE_amd64_PS\mount /Commit
Noticed that behavior of Powershell as well, the more the slower the system is. On some of my VM you can have several cups of coffee inbetween . DISKPART here is much more straight forward. Not asking any further questions is the only hook in here, as it instantly wipes all. Not that cool if you realize that you used wrong disk number. Had to recover a 1TB drive .
Probably of no use at all, but i use autoit to make a blank vhd with diskpart by simply echoing keystrokes to the cmd if you want to think outside the box. Code: Case $Button3 ;Create blank VHD $TargetVHD = FileSaveDialog("Target VHD file", "c:\", "name it Win.vhd (*.VHD)", 16) If Not @error Then If StringInStr($TargetVHD, "*.vhd") = 0 Then $TargetVHD = $TargetVHD & ".vhd" EndIf EndIf $SizeData = GUICtrlRead($Size) Opt("WinWaitDelay", 100) ; Diskpart create Run(@WindowsDir & "\system32\diskpart.exe") WinWaitActive(@WindowsDir & "\system32\diskpart.exe") ;Send("create{SPACE}vdisk{SPACE}file=" & $TargetVHD & "{SPACE}maximum=20000{SPACE}type=fixed{ENTER}") Send("create{SPACE}vdisk{SPACE}file=" & $TargetVHD & "{SPACE}maximum=" & $SizeData & "{SPACE}type=fixed{ENTER}") WinWaitActive(@WindowsDir & "\system32\diskpart.exe", "") Send("select{SPACE}vdisk{SPACE}file=" & $TargetVHD & "{ENTER}") WinWaitActive(@WindowsDir & "\system32\diskpart.exe", "") Send("attach{SPACE}vdisk{ENTER}") WinWaitActive(@WindowsDir & "\system32\diskpart.exe", "") Send("create{SPACE}partition{SPACE}primary{ENTER}") WinWaitActive(@WindowsDir & "\system32\diskpart.exe", "") Send("assign{SPACE}letter=W{ENTER}") WinWaitActive(@WindowsDir & "\system32\diskpart.exe", "") Send("format{SPACE}quick{SPACE}label=vhd{ENTER}")
Made my DISKPART/Apply script a lot more complicated. Added UEFI auto-detection Added Recovery partition and push-button reset image option Added diskpart echo command stuff Added Add-driver support (Raid on win7/2008r2 anyone?) for both winpe and setup installation Added Multi-Boot install options, though it's not foolproof since I haven't error handled the partition creation stuff yet Added an option to Not create the additional System partition for MBR/BIOS booting for the folks that like to quad-boot a mbr drive or triple-boot with recovery partition on mbr Added an option to not move the winre.wim during MBR/BIOS setup (would only move it during first setup anyway) I've worked out most of the kinks and even learned a thing or two. For instance did you know that Windows will be a little Bit** if you use a command like this? IF %ERRORLEVEL% EQU 0( Nay... you have to separate the 0 and the ( Also learned that you have to use winrecfg if you try to set the winre image from within a different architecture's boot.wim Here's the new script. It's pretty messy and disorganized, but if I'm doing a big no-no that you notice. Or if you have recommendations in general, I'm all ears. Srsly I was just trying to get it to work. It's far from perfect. Code: @ECHO OFF pushd %~dp0 Setlocal EnableDelayedExpansion :color and title color 1f title murphy78's Disk Partitioning and Apply Image Script mode con:lines=50 :Check whether user has booted with UEFI or BIOS and set UEFI=1 if UEFI wpeutil UpdateBootInfo for /f "tokens=2* delims= " %%A in ('reg query HKLM\System\CurrentControlSet\Control /v PEFirmwareType') DO SET Firmware=%%B :: Note: delims is a TAB followed by a space. if %Firmware%==0x1 set UEFI=0 if %Firmware%==0x2 set UEFI=1 :Set some defaults for later set DISK=0 set WINRE=1 set PUSHBUTTON=0 set MULTIBOOT=0 set NOSYSPART=0 SET MBRACTIVE=0 set DISKPREPARED=0 set ERRORTEMP=0 :MAINMENU CLS IF %UEFI% EQU 1 ( SET WINRE=1 SET NOSYSPART=0) IF %NOSYSPART% EQU 1 (SET WINRE=0) ECHO =============================================================================== ECHO =============================== DISK PARTITION ================================ ECHO ------------------------------------------------------------------------------- ECHO. L. - ^(L^)ist Disk by size and number ECHO. V. - ^(V^)olume listing of detected partitions ECHO. D. - ^(D^)isk selection ECHO ------------------------------------------------------------------------------- ECHO. P. - ^(P^)ush-button reset image partition flag IF %UEFI% EQU 0 ECHO. W. - ^(W^)inre.wim movement flag IF %UEFI% EQU 0 ECHO. N. - ^(N^)o extra system partition *MBR/BIOS-Boot only* ECHO ------------------------------------------------------------------------------- ECHO. A. - ^(A^)dd Driver to this WinPE session ECHO. S. - ^(S^)etup Windows ECHO ------------------------------------------------------------------------------- ECHO. C. - ^(C^)ommand Prompt ECHO. ECHO =============================================================================== if %UEFI% EQU 1 echo. * Disk %DISK% and GPT partitioning ^(UEFI-Booting Detected^) * if %UEFI% EQU 0 echo. * Disk %DISK% and MBR partitioning ^(BIOS-Legacy Detected^) * if %PUSHBUTTON% EQU 1 echo. * Push-button Recovery Image ENABLED * if %PUSHBUTTON% EQU 0 echo. * Push-button Recovery Image DISABLED * if %UEFI% EQU 0 (IF %WINRE% EQU 1 echo. * WINRE.WIM Movement ENABLED *) if %UEFI% EQU 0 (IF %WINRE% EQU 0 echo. * WINRE.WIM Movement DISABLED *) if %UEFI% EQU 0 (IF %NOSYSPART% EQU 1 echo. * NO System Partition ENABLED *) if %UEFI% EQU 0 (IF %NOSYSPART% EQU 0 echo. * NO System Partition DISABLED *) ECHO ------------------------------------------------------------------------------- ECHO =============================== PRESS 'Q' TO QUIT ============================= ECHO. choice /c lvdpwnascq /n /m "Choose a menu option, or Q to Quit" IF %ERRORLEVEL% EQU 1 (GOTO :SelectionL) IF %ERRORLEVEL% EQU 2 (GOTO :SelectionV) IF %ERRORLEVEL% EQU 3 (GOTO :SelectionD) IF %ERRORLEVEL% EQU 4 (GOTO :SelectionP) IF %ERRORLEVEL% EQU 5 (GOTO :SelectionW) IF %ERRORLEVEL% EQU 6 (GOTO :SelectionN) IF %ERRORLEVEL% EQU 7 (GOTO :SelectionA) IF %ERRORLEVEL% EQU 8 (GOTO :SelectionS) IF %ERRORLEVEL% EQU 9 (GOTO :SelectionC) IF %ERRORLEVEL% EQU 10 (GOTO :QUIT) :Break-handling IF %ERRORLEVEL% EQU 0 (GOTO :MAINMENU) :SelectionL echo. echo List Disk|diskpart echo.&echo Press any key to return to the menu. PAUSE > NUL & GOTO :MAINMENU :SelectionV echo. echo List Volume|diskpart echo.&echo Press any key to return to the menu. PAUSE > NUL & GOTO :MAINMENU :SelectionD GOTO :DISKMENU :SelectionP Echo Push-button reset image is for Windows 8+ and will not have the Echo functionality to mount recovery partition and replace the Windows Echo Files that exists if you are not using Windows 8 or higher. Echo Do you wish to change the status of this Flag? choice /c yn SET ERRORTEMP=%ERRORLEVEL% IF %ERRORTEMP% EQU 1 (IF %PUSHBUTTON% EQU 0 (SET PUSHBUTTON=1) ELSE (SET PUSHBUTTON=0)) IF %ERRORTEMP% EQU 2 (GOTO :MAINMENU) :break-handling IF %ERRORTEMP% EQU 0 (GOTO :MAINMENU) GOTO :MAINMENU :SelectionW IF %UEFI% EQU 1 GOTO :MAINMENU :Little warning and choice Echo Windows normally moves the WinRE.WIM recovery file to a separate partition. Echo MBR partitioning is limited to 4 partitions per drive. Echo Would you like to change the WINRE movement flag? choice /c yn SET ERRORTEMP=%ERRORLEVEL% IF %ERRORTEMP% EQU 1 ( IF %WINRE% EQU 0 (SET WINRE=1) IF %WINRE% EQU 1 (SET WINRE=0)) IF %ERRORTEMP% EQU 2 (GOTO :MAINMENU) :break-handling IF %ERRORTEMP% EQU 0 (GOTO :MAINMENU) GOTO :MAINMENU :SelectionN :Little warning and choice Echo Windows normally creates a separate partition. Echo MBR partitioning is limited to 4 partitions per drive. Echo Would you like to change the extra system partition option? choice /c yn SET ERRORTEMP=%ERRORLEVEL% IF %ERRORTEMP% EQU 1 ( IF %NOSYSPART% EQU 0 (SET NOSYSPART=1) IF %NOSYSPART% EQU 1 (SET NOSYSPART=0)) IF %ERRORTEMP% EQU 2 (GOTO :MAINMENU) :break-handling IF %ERRORTEMP% EQU 0 (GOTO :MAINMENU) GOTO :MAINMENU :SelectionC START CMD GOTO :MAINMENU :SelectionA echo Would you like to add a driver folder to the Windows PE? echo Example: Raid driver or USB3 driver choice /c yn SET ERRORTEMP=%ERRORLEVEL% IF %ERRORTEMP% EQU 1 ( SET INPUT= Echo Use the folder, separate multiples with comma: Echo Example: D:\DRIVERS\x64,D:\DRIVERS\USB3\x64 SET /P INPUT="Please type the path, C for CMD or Q to go back: " IF /I '%INPUT%'=='Q' GOTO :MAINMENU IF /I '%INPUT%'=='C' (START CMD & GOTO :SelectionA) Echo Attempting to add driver from %INPUT% drvload %INPUT% Echo Add driver process completed. Press any key to return to menu. pause>NUL GOTO :MAINMENU) GOTO :MAINMENU :SelectionS GOTO :SETUP :DISKMENU SET DISK=0 CLS echo List Disk|diskpart Echo. ECHO ------------------------------------------------------------------------------- ECHO. Select a disk number ^(0-9^) or M to return to the Main Menu ECHO ------------------------------------------------------------------------------- ECHO. ECHO Note that disk 0 is the first disk, and they might not appear in order. choice /c 0123456789Q /n /m "Choose a disk number, or Q to Quit back to menu:" SET ERRORTEMP=%ERRORLEVEL% IF %ERRORTEMP% EQU 1 (SET DISK=0) IF %ERRORTEMP% EQU 2 (SET DISK=1) IF %ERRORTEMP% EQU 3 (SET DISK=2) IF %ERRORTEMP% EQU 4 (SET DISK=3) IF %ERRORTEMP% EQU 5 (SET DISK=4) IF %ERRORTEMP% EQU 6 (SET DISK=5) IF %ERRORTEMP% EQU 7 (SET DISK=6) IF %ERRORTEMP% EQU 8 (SET DISK=7) IF %ERRORTEMP% EQU 9 (SET DISK=8) IF %ERRORTEMP% EQU 10 (SET DISK=9) IF %ERRORTEMP% EQU 11 (GOTO :MAINMENU) :Break-handling IF %ERRORTEMP% EQU 0 (GOTO :MAINMENU) Echo LIST DISK | DISKPART | find /i "Disk %DISK%" >NUL IF %ERRORLEVEL% NEQ 0 (GOTO :DISKMENU) GOTO :MAINMENU :SETUP SET INSTALLIMAGE= SET SPLIT=0 FOR %%i IN (Z Y X W V U T S R Q P O N M L K J I H G F E D C B A) DO IF EXIST %%i:\Sources\install*.* CD /D "%%i:\Sources\" IF Exist install.wim ( SET INSTALLIMAGE="install.wim" GOTO :GotImage ) IF Exist install.esd ( SET INSTALLIMAGE="install.esd" GOTO :GotImage ) IF Exist install.swm ( SET INSTALLIMAGE="install.swm" SET SPLIT=1 SET SPLITPATTERN=install*.swm GOTO :GotImage ) IF NOT EXIST %INSTALLIMAGE% ( Echo An install image has not been found. pause GOTO :QUIT :GotImage :THIS PART does the initial system and uefi partitions IF %DISKPREPARED% EQU 1 (GOTO :DISKPREPMSG) Echo.&Echo. Disk ### Status Size Free Dyn Gpt Echo. -------- ------------- ------- ------- --- --- Echo LIST DISK | DISKPART | find /i "Disk %DISK%" Echo.&Echo.&Echo Setup will now prepare Disk %DISK% for you. Echo This will erase all data on the target drive or raid. Echo Are you sure you wish to proceed? choice /c yn SET ERRORTEMP=%ERRORLEVEL% IF %ERRORTEMP% EQU 2 GOTO :MAINMENU :break-handling IF %ERRORTEMP% EQU 0 GOTO :MAINMENU :OK proceed with wiping disk %DISK% Echo SELECT DISK %DISK% >X:\DISKPART.TXT Echo CLEAN >>X:\DISKPART.txt :GPT VERSION IF %UEFI% EQU 1 ( Echo Convert GPT >>X:\DISKPART.txt Echo create partition primary size=300 >>X:\DISKPART.txt Echo format quick fs=ntfs label="Windows RE tools" >>X:\DISKPART.txt Echo assign letter="T" >>X:\DISKPART.txt Echo set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac" >>X:\DISKPART.txt Echo gpt attributes=0x8000000000000001 >>X:\DISKPART.txt Echo create partition efi size=100 >>X:\DISKPART.txt Echo format quick fs=fat32 label="System" >>X:\DISKPART.txt Echo assign letter="S" >>X:\DISKPART.txt Echo set id="c12a7328-f81f-11d2-ba4b-00a0c93ec93b" >>X:\DISKPART.txt Echo create partition msr size=128 >>X:\DISKPART.txt Echo set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac" >>X:\DISKPART.txt ) :MBR VERSION IF %UEFI% EQU 0 ( Echo Convert MBR >>X:\DISKPART.txt IF %NOSYSPART% EQU 0 ( IF %WINRE% EQU 1 ( Echo create partition primary size=450 >>X:\DISKPART.txt ) IF %WINRE% EQU 0 ( Echo create partition primary size=200 >>X:\DISKPART.txt ) Echo format quick fs=ntfs label="System" >>X:\DISKPART.txt Echo Active >>X:\DISKPART.txt SET MBRACTIVE=1 Echo assign letter="S" >>X:\DISKPART.txt ) IF %NOSYSPART% EQU 1 SET MBRACTIVE=0 ) :Run the script and delete it from the ramdrive diskpart /s X:\diskpart.txt set DISPREPARED=1 GOTO :PartitionCreation :DISKPREPMSG echo Disk preparation was already ran. echo Would you like to run it again? choice /c yn SET ERRORTEMP=%ERRORLEVEL% IF %ERRORTEMP% 1 (SET DISKPREPARED=0 & GOTO :GotImage)) :PartitionCreation :Start building DISKPART SCRIPT HERE :Just check the size of the selected disk to get space echo.&echo Setup Needs to create a Windows Partition echo Would you like to Create the partition? choice /c yn SET ERRORTEMP=%ERRORLEVEL% IF %ERRORTEMP% EQU 2 (GOTO :MAINMENU) :CreateSetupPartition SET INPUT= CLS Echo.&Echo. Disk ### Status Size Free Dyn Gpt Echo. -------- ------------- ------- ------- --- --- Echo LIST DISK | DISKPART | find /i "Disk %DISK%" Echo.&Echo Diskpart defaults to Megabyte size for partitions. ECHO ^(Ex: 100 = 100 MB, 1000 = 1 GB^) IF %UEFI% EQU 0 (Echo Note that MBR drives can only have 4 partitions.) IF %MULTIBOOT% EQU 0 (ECHO *Add 10000 to your number if you selected a push-button reset image.*) Echo. SET /P INPUT="Please select a Partition size, or M for Max, Q to return to menu: " IF /I '%INPUT%'=='Q' GOTO :MAINMENU Echo SELECT DISK %DISK% >X:\DISKPART.TXT IF /I '%INPUT%'=='M' (Echo CREATE PARTITION PRIMARY >>X:\DISKPART.TXT) ELSE ( Echo CREATE PARTITION PRIMARY SIZE=%INPUT% >>X:\DISKPART.TXT) :If not moving WinRE.WIM on MBR, make it active partition first time ran IF %WINRE% EQU 0 (IF %UEFI% EQU 0 (IF %MULTIBOOT% EQU 0 (Echo Active >>X:\DISKPART.txt))) :If pushbutton reset image, shrink to make room IF %PUSHBUTTON% EQU 1 (Echo SHRINK MINIMUM=10000 >>X:\DISKPART.txt) Echo format quick fs=ntfs label="Windows" >>X:\DISKPART.txt echo Assign Letter="W" >>X:\DISKPART.txt IF %PUSHBUTTON% EQU 1 (Echo Create partition Primary >>X:\DISKPART.txt ECHO format quick fs=ntfs label="Recovery image" >>X:\DISKPART.txt ECHO assign letter="R" >>X:\DISKPART.txt IF %UEFI% EQU 1 ( ECHO set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac" >>X:\DISKPART.txt ECHO gpt attributes=0x8000000000000001 >>X:\DISKPART.txt) IF %UEFI% EQU 0 (ECHO set id=27 >>X:\DISKPART.txt) SET PUSHBUTTON=0) :Execute the partition creation script diskpart /s X:\DISKPART.txt IF %ERRORLEVEL% NEQ 0 (Echo There were errors reported during partition creation. echo Press any key to go back to the main menu. pause>NUL GOTO :MAINMENU ) :ImageSelection SET INDEX= CLS ECHO =============================================================================== ECHO =============================== INDEX SELECTION =============================== :Display-Indexes for /f "tokens=2 delims=: " %%a in ('DISM /Get-WimInfo /WimFile:%INSTALLIMAGE% ^| find /i "Index"') do ( for /f "tokens=2 delims=:" %%g in ('DISM /Get-WimInfo /WimFile:%INSTALLIMAGE% /Index:%%a ^| find /i "Name"') do ( echo %%a.%%g ) ) ECHO ========================== SELECT INDEX OR Q TO EXIT ========================== SET INPUT= SET /P INPUT="Please select an Index Number or Q to exit to the Main Menu: " IF /I '%INPUT%'=='Q' GOTO :MAINMENU SET INDEX=%INPUT% :CheckIndex echo. DISM /Get-WimInfo /WimFile:%INSTALLIMAGE% /index:%INDEX% choice /c yn /m "Are you sure you wish to use this index?" IF %ERRORLEVEL% EQU 1 (GOTO :ApplyImage) ELSE (GOTO :ImageSelection) :ApplyImage CLS echo Script will now apply the %INSTALLIMAGE% Index %INDEX%. echo This will take a while... echo. IF %SPLIT% EQU 1 (dism /Apply-Image /ImageFile:%INSTALLIMAGE% /swmfile:%SPLITPATTERN% /Index:%INDEX% /ApplyDir:W:\ ) ELSE (dism /Apply-Image /ImageFile:%INSTALLIMAGE% /Index:%INDEX% /ApplyDir:W:\) attrib W:\windows\system32\recovery\winre.wim -r -s -h echo.&echo Adding boot information to the System partition bcdboot W:\Windows IF %MULTIBOOT% EQU 1 GOTO :ADDDRIVERS echo.&echo Setting up WinRE.WIM and the recovery option IF %UEFI% EQU 1 ( md T:\Recovery\WindowsRE move /y W:\windows\system32\recovery\winre.wim T:\Recovery\WindowsRE\winre.wim winrecfg /setreimage /path T:\Recovery\WindowsRE /target W:\Windows attrib T:\Recovery\WindowsRE\winre.wim +r +s +h) IF %UEFI% EQU 0 ( md S:\Recovery\WindowsRE move /y W:\windows\system32\recovery\winre.wim S:\Recovery\WindowsRE\winre.wim winrecfg /setreimage /path S:\Recovery\WindowsRE /target W:\Windows attrib S:\Recovery\WindowsRE\winre.wim +r +s +h) IF EXIST W:\Windows\system32\Recovery\WinRE.wim ( winrecfg /setreimage /path W:\Windows\system32\Recovery /target W:\Windows attrib +r +s +h W:\Windows\system32\Recovery\WinRE.wim) :Ask if user wishes to add drivers to the W:\Windows partition :ADDDRIVERS echo.&echo Would you like to add a driver folder for the Windows installation? echo You need to add things such as Raid drivers even if you already echo added them to the WINPE session. (Signed only) echo.&echo Example: Raid drivers for Windows 7/2008r2 choice /c yn SET ERRORTEMP=%ERRORLEVEL% IF %ERRORTEMP% EQU 1 ( SET INPUT= Echo Just type the parent folder, Ex: D:\DRIVERS\x64 SET /P INPUT="Please type the path, C for CMD or Q to go back: " IF /I '%INPUT%'=='Q' GOTO :ADDDRIVERS IF /I '%INPUT%'=='C' (START CMD & GOTO :ADDDRIVERS) Echo Attempting to add drivers from %INPUT% dism /image:W:\ /add-driver /driver:%INPUT% /recurse) :Capture the W:\Windows Image to the Recovery partition if using push-button reset image IF %PUSHBUTTON% EQU 0 GOTO :MULTIBOOTOPTION Echo.&ECHO Setting up the Push-Button Recovery Image on the Recovery partition MD R:\Recovery\ dism /capture-image /imagefile:R:\Recovery\install.wim /capturedir:W:\ /name:"Windows Recovery Image" /description:"Windows Recovery Image" /compress:max /checkintegrity /verify winrecfg /setosimage /path R:\Recovery /index 1 /target W:\Windows set PUSHBUTTON=0 :MULTIBOOTOPTION :Give option to create another partition and apply image, else quit Echo.&Echo SETUP HAS COMPLETED. Echo Would you like to create another partition and setup Multi-Boot? Echo Note that if you selected the max partition size previously or Echo have more than 4 partitions on an MBR drive it will not work. choice /c yn SET ERRORTEMP=%ERRORLEVEL% IF %ERRORTEMP% EQU 1 ( :Set multiboot flag SET MULTIBOOT=1 GOTO :PartitionCreation) IF %ERRORTEMP% EQU 2 (GOTO :QUIT) :Break-support IF %ERRORTEMP% EQU 0 (GOTO :QUIT) :QUIT :Your standard Thank you and goodbye screen ECHO =============================================================================== ECHO END OF THE SCRIPT: ECHO Would you like to (R)eset or (S)hutdown? ECHO =============================================================================== choice /c rs IF %ERRORLEVEL% EQU 1 %WINDIR%\system32\WPEUTIL.exe reboot IF %ERRORLEVEL% EQU 2 %WINDIR%\system32\WPEUTIL.exe shutdown :break-support IF %ERRORLEVEL% EQU 0 %WINDIR%\system32\WPEUTIL.exe shutdown The only files you would need to change would be to add winrecfg.exe and the mui for it from the pe files in the adk. I've noticed that the amd64's pe version has a different hash than the x86 version, but it's probably just because it's re-compiled and re-signed. You could also just add the packages to your winpe from the adk. Just don't forget the mui (en-us or whatever) Edit: I'm testing everything on this. I'll up a fairly bug-free version when I'm done, though it won't be idiot-proof with all the error handling
There's still a lot of debugging to do on this script, but I'll get to it after some sleep. There's a lot of weird little rules about nesting and how it affects variable setting and such... I'm not going to do all the error handling until the script is more or less how it needs to be. Unfortunately, some things like basic math will need to be left up to the user. I'll leave recommended defaults and do most of the work, but if people cannot figure out how not to assign huge partitions that their disk can't hold or something... well that's on them. I'm not gonna spend a year di**ing around with the set /a stuff and nesting things correctly just so some bonehead can get a "TOO LARGE" message. Everyone is more than welcome to help test stuff when I get this next set done, just hang on a day or two till I work out all the bugs I notice. You're all welcome to pick the scripting apart and use whatever you feel like for your own needs. This is just my hobby stuff...
Making good progress on my testing with the diskpart/apply project... Currently happy with most everything but multi-booting UEFI with win7/server2008r2 seems to fail. It's like their precious bcdboot files are getting overwritten by the further installs. Barring a major progress halt I should be done with this overhaul tomorrow. No, I don't mean as an April 1st joke, either. That's just a coincidence.