Windows Autopilot – Hardware Hash (HWID) Extraction with Group Tag
📌 Description
This PowerShell script is used to extract the Windows Autopilot hardware hash (HWID) from a device and save it as a CSV file directly to a USB drive. Each file is created with a unique filename based on device model, serial number, and timestamp.
During execution, you are prompted to enter a Group Tag. The Group Tag is written directly into the CSV file and is later used by Windows Autopilot to automatically assign the device to the correct device groups, deployment profiles, and Microsoft Intune policies.
This approach is commonly used when manually collecting hardware hashes instead of paying a hardware vendor to unpack devices and pre-register them in Autopilot. By extracting the HWID in-house (for example during OOBE) and saving it to USB, organizations can reduce costs, keep full control, and still ensure devices are fully prepared for automated deployment.
🚀 Features
Extracts Windows Autopilot hardware hash (HWID)
Automatically adds a Group Tag to the export
Creates unique CSV filenames per device
Exports directly to removable USB media
No vendor pre-registration required
🛠️ Prerequisites
1- PowerShell access during OOBE (press Shift + F10, then run
powershell)
2- Internet access (to install Get-WindowsAutoPilotInfo if missing)
3- USB storage device
<#
.SYNOPSIS
Extraherar HWID till USB och lägger till "Group Tag" som du anger vid körning.
Skapar unikt filnamn per maskin (modell + tidsstämpel).
#>
# === Kräver admin ===
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host "❌ Skriptet måste köras som administratör." -ForegroundColor Red
exit 1
}
# === Installera Get-WindowsAutoPilotInfo om det saknas ===
if (-not (Get-Command Get-WindowsAutoPilotInfo -ErrorAction SilentlyContinue)) {
try {
Install-Script -Name Get-WindowsAutoPilotInfo -Force -Scope CurrentUser -ErrorAction Stop
Write-Host "✅ Installerade Get-WindowsAutoPilotInfo." -ForegroundColor Green
} catch {
Write-Host "❌ Misslyckades att installera Get-WindowsAutoPilotInfo. Kör som admin eller installera manuellt." -ForegroundColor Red
exit 1
}
}
# === Välj USB (företräde: volym med etikett AUTOPILOT) ===
$usbDrive = Get-Volume | Where-Object { $_.DriveType -eq 'Removable' -and $_.DriveLetter -and $_.FileSystemLabel -eq 'AUTOPILOT' } | Select-Object -First 1 -ExpandProperty DriveLetter
if (-not $usbDrive) {
$usbDrive = Get-Volume | Where-Object { $_.DriveType -eq 'Removable' -and $_.DriveLetter } | Select-Object -First 1 -ExpandProperty DriveLetter
}
if (-not $usbDrive) {
Write-Host "❌ Ingen USB-enhet hittades." -ForegroundColor Red
exit 1
}
# === Fråga efter Group Tag ===
$groupTag = Read-Host "Ange Group Tag (t.ex. Kiosk-Bib-01)"
if ([string]::IsNullOrWhiteSpace($groupTag)) {
Write-Host "❌ Ogiltig Group Tag." -ForegroundColor Red
exit 1
}
# === Skapa unikt filnamn ===
$model = (Get-CimInstance Win32_ComputerSystem).Model.Trim() -replace '\s+', '_'
$sn = (Get-CimInstance Win32_BIOS).SerialNumber.Trim()
$date = Get-Date -Format "yyyyMMdd_HHmm"
$fileName = "${model}_${sn}_${date}.csv"
$filePath = "$usbDrive`:\$fileName"
# === Kör export till temporär fil ===
$tempCsv = Join-Path $env:TEMP "autopilot_$($sn)_$($date).csv"
try {
Get-WindowsAutoPilotInfo -OutputFile $tempCsv -ErrorAction Stop
Write-Host "✅ HWID extraherad." -ForegroundColor Green
} catch {
Write-Host "❌ Misslyckades att extrahera HWID: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}
# === Lägg till Group Tag och skriv slutfil ===
try {
$rows = Import-Csv $tempCsv
foreach ($r in $rows) {
if (-not ($r.PSObject.Properties.Name -contains 'Group Tag')) {
$r | Add-Member -NotePropertyName 'Group Tag' -NotePropertyValue $groupTag
} else {
$r.'Group Tag' = $groupTag
}
}
$rows | Export-Csv -Path $filePath -NoTypeInformation -Encoding UTF8
Write-Host "✅ Sparade CSV till USB: $filePath" -ForegroundColor Green
} catch {
Write-Host "❌ Misslyckades att skapa CSV: $($_.Exception.Message)" -ForegroundColor Red
exit 1
} finally {
Remove-Item $tempCsv -ErrorAction SilentlyContinue
}
Kommentarer
Skicka en kommentar