It seems as if every time I need to reload a physical system, I’m searching the Internet to find a way to create a bootable USB drive from a Windows 10 or Windows Server 2016 ISO. I always seem to find tutorials that are using a process that’s almost 20 years old. They have me using the diskpart command line utility. Diskpart which initially shipped with Windows 2000, reminds me way too much of its predecessor, the fdisk command line utility.
The PowerShell commands in this blog article are written to be compatible with PowerShell version 4.0 and higher. Windows 8 or Windows Server 2012 with a GUI or higher is also required because although you can install PowerShell version 4.0+ on older operating systems, many of the commands used in this blog article won’t exist on them. This is due to the newer WMI namespaces which the cmdlets rely on not existing on older operating systems. Out-GridView which is used in this blog article isn’t supported on Server Core (Windows Server without a graphical user interface).
To create a bootable USB drive from an ISO, insert the USB drive into your computer and launch PowerShell as an administrator. Run the following PowerShell one-liner. Warning: This command will permanently delete all of the data on the selected USB drive. Proceed at your own risk. You’ve been warned.
1 2 3 4 5 6 | $Results = Get-Disk | Where-Object BusType -eq USB | Out-GridView -Title 'Select USB Drive to Format' -OutputMode Single | Clear-Disk -RemoveData -RemoveOEM -Confirm:$false -PassThru | New-Partition -UseMaximumSize -IsActive -AssignDriveLetter | Format-Volume -FileSystem FAT32 |
Walking through the previous command, the first line gets a list of all the disks attached to the system. The second filters them to only ones that are USB drives. Those results are sent to Out-GridView for the user to select the USB drive to format in case more than one USB drive is attached to the system (you can only blame yourself if you select the wrong one).
The fourth clears all data and partitions off of the disk. The fifth creates a new partition using all of the available space on the USB drive and assigns a drive letter to it. The last line formats the USB drive. While many tutorials use NTFS as the type of file system, I found that my Lenovo ThinkPad P50 will not boot from a Windows 10 USB drive formatted with NTFS. It boots fine from one formatted with FAT32. Trying to use FAT32 for Windows Server 2016 generates an error though, so you’ll need to use NTFS for it.
Mount the ISO. The problem I ran into is there’s no easy way to determine what drive letter is assigned to an ISO once it’s mounted. The simplest way I found is to compare the drive letters before and after mounting it. While this sounds simple, another problem I ran into was that Compare-Object doesn’t handle null values.
1 2 3 | $Volumes = (Get-Volume).Where({$_.DriveLetter}).DriveLetter Mount-DiskImage -ImagePath C:\ISO\SW_DVD5_Win_Pro_Ent_Edu_N_10_1709_64BIT_English_MLF_X21-50143.ISO $ISO = (Compare-Object -ReferenceObject $Volumes -DifferenceObject (Get-Volume).Where({$_.DriveLetter}).DriveLetter).InputObject |
Change directory into the boot folder on the drive of the mounted ISO. Make the drive bootable and copy the contents of the ISO to the USB drive.
1 2 3 | Set-Location -Path "$($ISO):\boot" bootsect.exe /nt60 "$($Results.DriveLetter):" Copy-Item -Path "$($ISO):\*" -Destination "$($Results.DriveLetter):" -Recurse -Verbose |
While I’ve tried to do as much of this process as possible in PowerShell, there’s still a need to use a few command line utilities to accomplish this task. Thankfully, it’s something that you shouldn’t have to do very often. For ease of reuse, label your USB drive with a label maker, not a permanent marker.
The original version of this blog article used xcopy.exe to copy the files. That portion of this blog article has been updated to use the PowerShell Copy-Item cmdlet.
µ
Please describe what this USB drive can do when booted from it. Is it just for Windows installation? Do we get something like BartPE? A command shell? A full OS? Thanks!
The USB drive created in this blog article is a replacement for having to burn an ISO to a DVD in order to reload the operating system on a physical computer.
Hi Mike
You could use the -NoDriveLetter switch and WMI to assign to a letter of your choice
cf:
https://social.technet.microsoft.com/Forums/scriptcenter/en-US/d2faa6c3-35e8-4bad-8ac8-24902bbb6f1a/what-is-the-point-of-nodriveletter-in-mountdiskimage?forum=ITCG
Is the code to this on a github or some place? A link to that would be nice.
Thanks Mike for a Great Blog Post. Very Helpful.
The error you get with Server 2016 and FAT32 is because the install.wim file is bigger than 4GB. You need to use dism /split-image to copy the install.wim on the USB key.
Trying your script to make an usb bootable with last windows insider 18860 but have this issue
Container cannot be copied onto existing leaf item
error is about this line
Copy-Item -Path “$($ISO):\*” -Destination “$($Results.DriveLetter):” -Recurse -Verbose
and i don’t understand why
Wow! Windows stinks up the joint!
NO simple ISO utility. NO simple zip/unzip utility.
Go Linux!
For getting the Volume letter you can do:
$DiskLetter = Mount-DiskImage -ImagePath C:\ISO\SW_DVD5_Win_Pro_Ent_Edu_N_10_1709_64BIT_English_MLF_X21-50143.ISO | Get-Volume | Select-Object -ExpandProperty DriveLetter
For the mounted drive letter you can do:
$DiskImage = Mount-DiskImage -ImagePath C:\ISO\SW_DVD5_Win_Pro_Ent_Edu_N_10_1709_64BIT_English_MLF_X21-50143.ISO | Get-DiskImage | Get-Volume | Select-Object -ExpandProperty DriveLetter
Can yo please tell me why ths is not working … thanks.
PS G:\boot> Set-Location -Path “$($ISO):\boot”
>> bootsect.exe /nt60 “$($Results.DriveLetter):”
>> Copy-Item -Path “$($ISO):\*” -Destination “$($Results.DriveLetter):” -Recurse -Verbose
bootsect {/help|/nt60|/nt52} {SYS|ALL|:} [/force] [/mbr]
Boot sector restoration tool
Bootsect.exe updates the master boot code for hard disk partitions in order to
switch between BOOTMGR and NTLDR. You can use this tool to restore the boot
sector on your computer.
Run “bootsect /help” for detailed usage instructions.
VERBOSE: Performing the operation “Copy Directory” on target “Item: G:\boot Destination: G:\boot\:”.
VERBOSE: Performing the operation “Create Directory” on target “Destination: G:\boot\:”.
Copy-Item : The given path’s format is not supported.
At line:3 char:1
+ Copy-Item -Path “$($ISO):\*” -Destination “$($Results.DriveLetter):” …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Copy-Item], NotSupportedException
+ FullyQualifiedErrorId : System.NotSupportedException,Microsoft.PowerShell.Commands.CopyItemCommand
Never mind. I figured it out.