Collect an Autopilot Hardware Hash With PowerShell

Written by

in

I recently had a rush order of laptops come in from a supplier we don’t normally use. Our usual supplier registers new devices for Autopilot before they ship, but this one didn’t, so I had to collect the hardware hashes myself.

Here is the PowerShell script I used. It grabs the hash and saves it as a CSV, ready to import into Intune.

No extra modules, no downloads. It uses what is already built into Windows.

What the script does

It reads the hash from the device itself, adds the serial number, and writes a CSV in the format Intune expects.

You can also add a group tag, which is handy if you sort devices into Autopilot profiles by tag.

Getting to a desktop from the OOBE

A brand new laptop sits at the out-of-box experience (OOBE), the first setup screen, with no desktop to run anything from. You can get past it without setting anything up.

  1. At the first OOBE screen, press Ctrl + Shift + F3.
  2. The laptop restarts into audit mode and lands on a desktop, with a System Preparation Tool window open.
  3. Run the script from there (steps below).

Audit mode signs you in as the built-in administrator, so the script gets the admin rights it needs.

How to use it

  1. Get the script from my GitHub repo and copy it onto the device, a USB stick works well.
  2. Open PowerShell as administrator. The script will stop with a clear message if you forget.
  3. Run it from the folder where you saved it.
powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\Get-AutopilotHardwareHash.ps1

Want a group tag and a specific output path? Add the parameters.

.\Get-AutopilotHardwareHash.ps1 -GroupTag "Sales" -OutputFile C:\Temp\hwid.csv

With no parameters, it saves AutopilotHWID.csv in the current folder. Copy the CSV off the device before you carry on.

Going back to the OOBE

If you used audit mode, put the laptop back to its first-run state before you hand it on.

  1. In the System Preparation Tool window, set the cleanup action to Enter System Out-of-Box Experience (OOBE).
  2. Leave Generalize unticked.
  3. Set the shutdown option to Reboot and click OK.

Importing the CSV into Intune

  1. Open the Intune admin center and go to the Windows Autopilot devices page.
  2. Choose Import and select your CSV.
  3. Wait for the import to finish, then check the device appears in the list.

Imports can take a few minutes, so give it a moment before you panic.

Good to know

  • It only works on the device you are collecting from, so run it on each one.
  • If the hash is not available, the script tells you rather than saving an empty file.
  • Test it on one device first and check the CSV imports cleanly before you roll it out.

The script is free to use and change under the MIT licence. Give it a spin and let me know how you get on.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *