Command Script for installing Windows 10 from a single USB device
The solution described in this guide will create a Windows 10 deployment device. Windows deployment can be accomplished using a single USB, as described in this guide. Often USB deployment solutions describe using two USB devices; USB-A for the bootable WinPE and USB-B for the data volume containing the Windows image and additional resources. This guide will show how you can build a single USB for use when deploying Windows to PCs with just one USB port, or if you just want to do this using a single USB.
Although this solution describes a USB device, it is fairly simple to modify this script for use with a network.
The USB device will be created using the Windows ADK (Assessment and Deployment Kit). It will contain two partitions;
- FAT32 WinPE bootable partition
- NTFS partition for the Windows 10 image and other resources, such as scripts
Important: FAT32 file system has a maximum file size of 4GB. Most Windows images are larger than 4GB and WinPE must reside on a FAT32 partition. Therefore, you will not be able to store Windows images in the WinPE partition and must store them in a separate NTFS partition, or on a network share and this is the reason we will create two partitions. Some types of USB keys will not support multiple partitions, if you encounter this issue, you will need to try a different device (external USB hard drives will always support multiple partitions).
- A USB device of 16GB or greater
- A technician PC with the Windows ADK installed and at least 32GB free disk space
- Wininstall script from this repository
- A Reference PC (or virtual machine)
- A Target PC (or virtual machine)
- A Windows 10 image in .wim format
See this page for more details about Technician PC requirements
- Install the Windows ADK on your Technician PC. If you do not already have the latest Windows ADK installed (including the Windows PE add-on), you can download it from Microsoft at this link: https://docs.microsoft.com/en-us/windows-hardware/get-started/adk-install
- Create a new Windows PE (WinPE) using the Windows ADK. The following command will create a 64-bit custom WinPE located at c:\WinPE\amd64 and the WinPE will be named amd64
copype amd64 c:\WinPE\amd64
In this guide, I use 64-bit, but all commands are similar for 32-bit. Check this Microsoft website for details if you need to create a 32-bit environment
- Create a folder for mounting images. It can be any location you like, but typically I place my Mount folder in the root of the C drive
MD C:\Mount\WinPE
- Mount the new WinPE, using DISM
dism /mount-image /imagefile:"c:\WinPE\amd64\media\sources\boot.wim" /index:1 /mountdir:"C:\Mount\WinPE"
In this example, the following OCs are added;
- WMI
- .Net Framework
WMI OC and its English language component
dism /image:"c:\mount\winpe" /add-package /packagepath:"c:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-WMI.cab"
dism /image:"c:\mount\winpe" /add-package /packagepath:"c:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-WMI_en-us.cab"
DotNet Framework and its English language component
dism /image:"c:\mount\winpe" /add-package /packagepath:"c:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-NetFx.cab"
dism /image:"c:\mount\winpe" /add-package /packagepath:"c:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-NetFx_en-us.cab"
Open the Startnet.cmd file using Notepad
notepad c:\Mount\WinPE\Windows\System32\startnet.cmd
Add a Call to the wininstall.cmd script - We will save winistall.cmd to the 2nd partition or a network path as discussed later in this guide.
wpeinit
@ECHO OFF
FOR %%i IN (C D E F G H I J K L N M O P Q R S T U V W X Y Z) DO (
IF EXIST %%i:\scripts\wininstall.cmd (
CALL %%i:\Scripts\wininstall.cmd
)
)
-
The first command initializes WinPE and should already exist in the Startnet.cmd, meaning you should not need to add it.
-
The second command turns off the verbose echoing of every command. This is optional, but makes usage cleaner.
-
The third command is a loop to check which drive letter is assigned to the location where the ininstall.cmd script is saved and if found, runs the wininstall.cmd script.
Important: When you save the file, you should close all open file handles, for example, close File Explorer or navigate out of the Mount folder or the WinPE folder. Failing to close any open file handles will cause errors when unmounting the WinPE.
Optional: You can verify if WinPE has been successfully modified by running the following commands and examining the output
dism /get-mountedimageinfo
dism /image:"c:\Mount\WinPE" /get-pesettings
dism /image:"c:\Mount\WinPE" /get-packages
Save the changes you have made to WinPE
dism /unmount-image /mountdir:"C:\Mount\WinPE" /commit
Note: If you do not want to save the changes you have made, use the /discard option, for example
dism /unmount-image /mountdir:"C:\Mount\WinPE" /discard
-
Connect the USB device to the Technician PC
-
Determine the disk number for the USB device, using Diskpart
Diskpart
List Disk
Exit
- Create the FAT32 WinPE partition and NTFS data partition on the USB using Diskpart
Warning! Running these commands will erase all content on the USB device.
Diskpart
List Disk
Select Disk [disk number]
Clean
Create Partition Primary Size=2000
Format Quick fs=fat32 Label="WinPE"
Assign Letter=E
Active
Create Partition Primary
Format fs=ntfs Quick Label="USB-B"
Assign Letter=F
List Volume
Exit
Important: in the 3rd command, enter the disk number for the USB device, in place of the
[disk number]
command placeholder. For example, if Diskpart tells you the USB device is Disk 3, enterSelect Disk 3
for the 3rd command. If you do not know the disk number, Diskpart can tell you by runninglist disk
and noting the disk number.
Note: If running the Diskpart commands manually, rather than from a script, Windows will prompt you to format the partition by a dialog once you create the partition. You can close the dialog since you are performing the commands manually using Diskpart. This is just plug and play detecting the new partition and is expected.
Note: Sometimes drive letters will vary, depending on the configuration of the device. Sometimes the drive will be detected as E and other times it can be F or another letter.
Example view of Disk Management showing the completed USB partitions
Note: You can assign any available drive letters you wish and do not need to use E and F as shown. Also, you can set the label to anything if you want to assign different description labels.
The makewinpemedia.cmd script comes built-in to the Windows ADK and generates bootable media, either an ISO file or bootable USB.
- To create an ISO (for use on a virtual machine). This example will create an ISO file named amd64.iso saved to the D drive
makewinpemedia /iso c:\WinPE\amd64 d:\amd64.iso
- To create a bootable USB
makewinpemedia /ufd c:\WinPE\amd64 E:
Warning! Running this command will erase all content on the USB devices E partition.
Reminder: On your system, the USB drive may not be drive E. Ensure that you are providing the correct drive letter where you want to install WinPE onto the USB. You can easily see this using the Disk Management tool.
- Create a Scripts folder on the 2nd partition and name it Scripts
MD F:\Scripts
- Create an Images folder on the 2nd partition and name it Images. You may want to create a folder for both 32-bit and 64-bit
MD F:\Images\x86
MD F:\Images\x64
-
Copy the Wininstall.cmd files to the Scripts folder, for example to the F:\Scripts folder
-
Copy a Windows 10 image to the Images folder, for example to the F:\Images\x64 folder
-
Boot a Reference PC (or virtual PC) to the WinPE created in the steps above
-
WinPE should initialize and locate the partition where the wininstall.cmd file is located
-
Wininstall.cmd should launch and prompt to install either Windows 10 Home or Windows 10 Pro
-
Make the OS version selection and press Enter
-
When Windows installation completes, you can press and hold the power button to power down the PC or type
exit
to reboot -
On next boot, the device will boot to the Windows Out of Box Experience (OOBE)
Note: You should boot the device to OOBE in the factory so that you can perform a final qualitiy check and so that when the end-user next boots, the device will not need to go through plug and play detect again and it will boot faster.
-
From the first OOBE screen, press
Shift + F10
keys to open the command prompt -
Type
devmgmt.msc
to launch Device Manager. Inpect the device drivers and update drivers if needed, then close Device Manager.
Important: Do not create a user account - that is for the end-user to do. If you do, you will need to run Sysprep to prepare the installation for the end-user again.
-
Power down the PC by holding the power button for 10 seconds or type
shutdown -s -t 0
at the command line -
Process the device by placing it into inventory or providing it to the end-user
Desktop manufacturing https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/
Windows 10 DISM Command-Line Options https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/deployment-image-servicing-and-management--dism--command-line-options
Windows Commands https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands