Use PowerShell to create a bootable USB drive from a Windows 10 or Windows Server 2016 ISO

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.

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.

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.

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.

µ

6 Comments

  1. Bob

    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!

    Reply
  2. Tony R Auby

    Is the code to this on a github or some place? A link to that would be nice.

    Reply
  3. Steve

    Thanks Mike for a Great Blog Post. Very Helpful.

    Reply
  4. Marc

    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.

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: