Create a zero-touch Windows 10 setup USB key

Intro

As you move more modern deployment and get away from traditional imaging, there still comes a time when you as an IT admin need to cleanly install Windows 10 on a device. This could be due to hard drive failure., SSD upgrade, or the OS is too far corrupted to do a full PC reset. Or like me, sometimes you’re just lazy. Not only that, using a third party tool such as Rufus to make a Windows 10 ISO bootable to a USB drive can often not work due to varying hardware support for NTFS UEFI booting. The UEFI standard is most commonly implemented with FAT32 support. The downside is that the Win10 media can’t fit onto FAT32 because the install.wim file is over 4GB. The process I’ll document here will enable a super simple way to make a bootable USB drive with WIndows 10 Setup media that supports UEFI (and legacy) booting on the widest range of hardware. It will also fully install Win10 with zero-touch.

Pre-reqs:

  • 8 GB or larger USB key. I recommend using a fast drive such as Sandisk Extreme or an external SSD via USB 3.0
  • Windows 10 Setup media downloaded from MS Volume license site or MSDN
  • Laptop running Windows 10 1803 or newer (this is so you can actually see the multiple partitions on the USB key)

Main Script

Go to the “Windows 10 Automated Setup Media” Github repo and download the “Create-Win10-Media.ps1” script. Tips for those unfamiliar:

Click on script and then “raw” and then right click the page and “save as”

Or go here to download it and the browse to the script (AirWatch-samples-master\Windows-Samples\Tools & Utilities\Windows 10 Automated Setup Media\Create-Win10-Media.ps1)

You might need to allow it to run in the execution policy

Right click “Run with Powershell” (this will self elevate and run “as administrator”)

Before continuing with script, ensure you have downloaded the appropriate Windows 10 media from MS Volume License site, MSDN, or used the MediaCreationTool to create an ISO (I touch more on this tool at the end)

Right click the ISO and mount it with explorer so that it gets a drive letter assigned. In my case in will be “F:\”

At the script, enter drive letter (including colon and slash) of Win10 Media. Enter.


Enter drive letter (including colon and slash) of Win10 Media

Plug in your USB drive. The script will search for available USB drives and present you a list.

Select the drive number of the one you want (probably will be drive 1 as drive 0 is your internal disk). Enter.

It will ask you to double check you have select the correct drive as it will wipe out the whole thing. If correct, hit “y”.

The script will then wipe the USB key and do the following:

  • First partition will be a 500 MB FAT32 partition that holds all of the boot files from windows setup media
  • The second partition will be the remaining space on the drive formatted as NTFS.
  • This partition will only have the Sources folder which contains the install.wim file. FAT32 doesn’t support files sizes over 4 GB so we needed to make this partition NTFS formatted. It also gives much faster transfer speeds so Windows 10 installs very quickly.

Once the files are copied, copy the Autounattend.xml file into the root of the “USB-BOOT” partition. This will enable Windows 10 Setup to be fully automated and zero touch. If you don’t include this file you’ll need to manually click through the Windows 10 setup wizard. More on this file next:

Autounattend.xml

We use a file called “autounattend.xml” to automate windows 10 setup process. Windows 10 setup will process this file if it resides in the root of the USB key. It acts like an unattend file for the WinPE setup process including formatting the disks, applying the correct SKU, and language. The one I include in this process is for GPT/UEFI as I am assuming you are going to be formatting it that way (yes, yes you definitely want to do this). But you can update it with MBR/Legacy boot mode. See MS documentation for some steps on how to do that as well as other things you can add to this file.

Let’s take a quick look at this file and what it is doing:

Formatting Disk 0 to GPT format (edit the file to see each partition)

Modifies those partitions to be have correct format and ID (in the case of recovery partition)

Language as English

Operating System SKU (based on the name of the OS).

Note: Windows 10 media comes with many different SKUs (Education, Enterprise, etc). If you would like Windows 10 Setup to install a different version, edit the autounattend.xml file in the root of the USB drive and update the name of the SKU you desire in the “ImageInstall” node in the XML. For example, to change from Win10 Pro to Win10 Enterprise you would update the “Value” key to be: Windows 10 Enterprise

We do add one tiny additional file (called ei.cfg) to tell windows to go ahead and format without Windows 10 product key. The script you ran above automatically creates it for you in the Sources folder on the NTFS formatted partition. If you neglect to include this file, then Windows 10 Setup will complain about invalid product key and error out.

And you’re done! Simply plug into any laptop (or VM) that is correctly set to boot EFI mode and boot to the USB drive (F12 on Dell machines, ESC on VMs, other devices might be different) and watch Windows 10 automatically install. On fast USB 3.0 media applying to a newer SSD laptop, I’ve seen install times as fast a 9 min! Here’s a quick video of this in action on a VM:

Microsoft Media Creator

One note on Microsoft’s tool. This tool does a similar thing as my script but it has some limitations:

  1. Each time you run it, it fully downloads the media from the internet. This makes it a much longer process if you are needing to re-do the process or setup multiple drives
  2. It is only the latest version of Windows. Right now, 1809 is the latest version, but if you needed 1803 or earlier it does not give you an option to select an earlier version.
  3. It is only Windows 10 Pro
  4. On the upside, the install.wim is compressed to under 4GB so it can fit on FAT32 partitions and thus allow you to have only 1 partition on the key (as opposed to 2 with my process)

This Post Has 4 Comments

  1. Really looking great, unfortunately I tried it today and got this error copying the some of the files, and it stops. I was running PS as admin.

    Add-Content : Access to the path ‘G:\sources\ei.cfg’ is denied.
    At C:\Users\Moudy.Abdelrahman\Downloads\AirWatch-samples-master\Windows-Samples\Tools & Utilities\Windows 10 Automated Setup Media\Create-Win10-Media.ps1:90 char:1
    + Add-Content -Path $usb_source\sources\ei.cfg -Value “[CHANNEL]”
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : PermissionDenied: (G:\sources\ei.cfg:String) [Add-Content], UnauthorizedAccessException
    + FullyQualifiedErrorId : GetContentWriterUnauthorizedAccessError,Microsoft.PowerShell.Commands.AddContentCommand

    Add-Content : Access to the path ‘G:\sources\ei.cfg’ is denied.
    At C:\Users\Moudy.Abdelrahman\Downloads\AirWatch-samples-master\Windows-Samples\Tools & Utilities\Windows 10 Automated Setup Media\Create-Win10-Media.ps1:91 char:1
    + Add-Content -Path $usb_source\sources\ei.cfg -Value “Retail”
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : PermissionDenied: (G:\sources\ei.cfg:String) [Add-Content], UnauthorizedAccessException
    + FullyQualifiedErrorId : GetContentWriterUnauthorizedAccessError,Microsoft.PowerShell.Commands.AddContentCommand

    1. Hi Moudy,

      Good catch. I’ve fixed the issue and re-uploaded it to github. Let me know if you still have issues.

      Brooks

  2. Thanks for the quick reply, I have tried the new copy on git but failing in removing a file. I got another question as well, I can use my custom answer file it wouldn’t be an issue, or do I have to use the one provided in the zipped file?

    Remove-Item : Cannot find path ‘G:\sources\ei.cfg’ because it does not exist.
    At C:\Users\Mahmoud\Downloads\Compressed\AirWatch-samples-master\Windows-Samples\Tools & Utilities\Windows 10
    Automated Setup Media\Create-Win10-Media.ps1:91 char:1
    + Remove-Item $usb_source\sources\ei.cfg -Force
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (G:\sources\ei.cfg:String) [Remove-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand

  3. A quick update……………..
    Even-though the copying failed with error above but it still worked and I was able to successfully install Windows 10 1809 via the USB drive. Awesome work Brooks, really great stuff. Thanks for sharing the knowledge.

Leave a Reply