How to Create Windows Bootable USB Stick using PowerShell

Windows PowerShell, as the name suggests is very powerful allowing us to communicate directly with the kernel, the inner most component of the OS. PowerShell has in its arsenal a bloat load of cmdlets, small utility programs that are useful for system management and administrative tasks such process listing, copying/moving files, network configuration etc. Today we’ll learn how to create a Windows-10 bootable USB stick using just the PowerShell.

Bootable USB device works better and faster than the OS CD/DVD. And we usually have a USB stick within our reach than an empty CD or DVD to burn the OS into.

While there are some pretty neat tools for creating bootable USB drive for Windows such as PowerISO (my personal favorite), Rufus, YUMI, Windows USB/DVD Download Tool and many more, PowerShell already has everything to turn our USB drive into a bootable medium. This is particularly handy if you’re inside an Intranet wherein third party tools are forbidden to be installed on the system.

Fire up the PowerShell as Administrator (by right-clicking and choosing run as administrator) and follow these steps in order to create a Windows-10 bootable USB drive:

Step #1: Mount the Windows OS ISO image

If you haven’t downloaded the Windows-10 disk image yet,  you can get the latest build from here. Once you have the iso image, mount it on the file system like so,

Mount-DiskImage -ImagePath "OS image path"

powershell-mount-diskimage

Note that you need to give the correct and full path of the OS image for the command to be run without any errors.

Once ISO image gets mounted, you can verify it in the Windows File Explorer. Make a note of the ISO’s DriveLetter which in my case is ‘H’.

diskimage-mounted

Note: Windows-10 OS file is around 4.5 GB. Choose an USB stick whose capacity is more than that.

Step #2: Prepare the USB drive

We need to get our USB ready before we turn into a bootable medium. Perform the following tasks in order.

i) Insert the USB pendrive and identify it from the disk list

Get-Disk

powershell-get-disk-cmdlet

Note down the disk number representing the USB drive. Here it’s 1. It may vary in your PC.

ii) Format the USB Drive

Clear-Disk -Number "n" -RemoveData

powershell-clear-disk-usb-formatting

The Number option should match to that of the USB we obtained in the previous command.

Pay attention to the warning message and make sure it’s the right disk (USB) you’re formatting before acknowledging [Y]es.

At most care should be taken when entering the disk number ‘n’ (1 in my case), double checking that it really is the USB drive ID which you got in the previous step. Otherwise you may end up formatting your hard disk partition and lose all the data it contains. None can get your data back, not even Rajnikanth!

iii) Create a new partition on the USB

New-Partition -DiskNumber "n" -UseMaximumSize -IsActive:$true

powershell-new-partition

Here the IsActive option marks the USB drive bootable should it has a bootloader, something which can’t be done via GUI. And the UseMaximumSize tells to partition the whole of USB into a single partition. Make a note of the DriveLetter (‘G’).

iv) Format the USB volume

Format-Volume -FileSystem NTFS -DriveLetter "USB_DRIVE_LETTER"

powershell-format-volume

Again care should be exercised when entering the DriveLetter, the one you got in the previous step. In my case it’s G.

Step #3: Make the USB Bootable

bootsect.exe /NT60 "USB_DRIVE_LETTER"

Bootsect is a utility that updates the master boot code for hard disk partitions. It makes our USB bootable by adding a bootstrap code. Learn more about bootsect.

powershell-bootsect

Step #4: Copy all files within the ISO image into the USB drive

Copy-Item -Recurse "Mounted_ISO_Drive\*" "USB_DRIVE" -verbose

powershell-copy-item-recurse

Do note that the mounted Windows ISO image DriveLetter ‘H’, the one which we got in step #1.  The Windows-10 ISO is around 4.5 GB which would take considerable amount of time to get copied into our USB. Go prepare yourself a cup of coffee in the meantime.

Once it’s done, our USB is ready to be booted on a PC/Laptop to install Windows-10 or to perform troubleshooting tasks.

Advertisements