How to upload Autopilot hashes from SCCM into Intune using PowerShell

Ondrej SebelaOndrej Sebela
2 min read

I was in need to gather Autopilot hashes to be able to migrate a subset of our SCCM clients into Intune to leverage the Autopilot feature.

Get Autopilot hashes from SCCM

As you may know, SCCM automatically gathers Autopilot hash from every Windows client during the Hardware inventory cycle. Such hash is then stored in the SCCM database so I've created a little PowerShell function Get-CMAutopilotHash (part of my SCCMStuff module) to get such hashes.

There is a bug in the new Windows Update that causes an error "Get-CimInstance : A general error occurred that is not covered by a more specific error code." when gathering the Autopilot hash. A temporary solution could be uninstalling such update wusa.exe /uninstall /KB:5013942 /norestart.

Upload Autopilot hashes into Intune

In general, you can upload Autopilot hashes manually or by Graph API. I've chosen the latter and created a function Upload-IntuneAutopilotHash (part of my IntuneStuff module).

Upload-IntuneAutopilotHash function supports setting of Autopilot device hostname, owner and groupTag. Can be run against local computer (gathers its hash) or accepts object with specific properties (SerialNumber, HardwareHash, Hostname, ownerUPN). Detailed information can be found in function help (Get-Help Upload-IntuneAutopilotHash -Full)

Result

And the result can look like this ๐Ÿ‘‡

# install necessary modules
Install-Module IntuneStuff
Install-Module SCCMStuff

# get Autopilot hashes for selected devices
$data = Get-CMAutopilotHash -computername pc-01, pc-02, pc-03
# (optional) set OwnerUPN so the Autopilot devices have associated same owners as are in SCCM
$data = $data | select *, @{n='OwnerUPN';e={$_.Owner + "@contoso.com"}}

# connect to your AAD tenant
Connect-AzureAD

$data | Foreach-Object {
  Upload-IntuneAutopilotHash -psObject $_ -Verbose
}
0
Subscribe to my newsletter

Read articles from Ondrej Sebela directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ondrej Sebela
Ondrej Sebela

I work as System Administrator for more than 10 years now and I love to make my life easier by automating work & personal stuff via PowerShell (even silly things like food recipes list generation).