Digital Marketing Agency | SEO, Paid Social & PPC

Managing Windows AutoPilot devices using the Intune Graph API

Share This Post

A while back, I published a sample script called Get-WindowsAutoPilotInfo, which is designed to help define existing computers with the Windows AutoPilot deployment service to manage Windows AutoPilot.

Some people have asked to take this one more step to automate uploading the gathered hardware details. Fortunately, this can be done using the Intune Graph API (exactly what the Intune portal uses behind the scenes). To show you how to do that, I’ve published a sample PowerShell module called WindowsAutoPilotIntune on the PowerShell Gallery.

How To Manage Windows AutoPilot

Here is an overview of how to use it:

Install the needed modules

There are two modules needed, the WindowsAutoPilotIntune module and the AzureAD module that it uses for authenticating with Intune. These can both be installed using the Install-Module PowerShell cmdlet:

Install-Module AzureAD
Install-Module WindowsAutoPilotIntune

Then we can exercise it a little by getting a list of the devices that have already been uploaded. But, first, load the module and connect to Intune by first specifying the user to use:

Import-Module WindowsAutoPilotIntune
Connect-AutoPilotIntune

After specifying the user principle, you’ll be prompted for a password (and if this is the first time you’ve used the Intune Graph APIs, you’ll also be prompted for permission). Make sure you specify a user that has sufficient rights. (Note that the authentication will time out after some time – the Azure AD sign-in process generates an access token that only has a limited life.)

Then you can get a list of devices:

Get-AutoPilotDevice

So let’s try something a little more involved: Adding some new devices. I’ll start with a CSV file created with the previously-mentioned Get-WindowsAutoPilotInfo script. It has five machines in it, one of which have already been imported (to show what an error looks like):

Import-AutoPilotCSV -csvFile C:Demo.csv

As each device is added to Intune, each new object created in Intune is returned and displayed. But that doesn’t mean that they are immediately added to the AutoPilot deployment service. Instead, Intune takes care of this as a background process running asynchronously. Thus, we can check on the progress to see if it is done yet, and once it is done, we can see if the devices were added successfully. How To Manage Windows AutoPilot.

Managing Windows AutoPilot devices

The script keeps checking every couple of seconds and shows you the number still being worked on. It looks like there is no progress being made, but then all are complete simultaneously (all parts of the same batch). Once all the devices are done, the final status is retrieved and displayed, and as we can see, 4 devices were added successfully, while one had a 640 StorageError (which means the device is already registered).

You may also like How to Move Windows 10 to SSD (Solid-State Drive)

One final step is performed after the final status is retrieved: an object for each device is deleted, leaving just the four new devices, which can be seen with the original Get-AutoPilotDevice cmdlet.

Check out the Import-AutoPilotCSV function to see a few other functions that are used to complete this task:

  • Get-AutoPilotImportedDevice, which retrieves the status objects for each device being added.
  • Add-AutoPilotImportedDevice, which adds the device. (Notice that you can specify an order ID for these devices, which could be useful for grouping devices using dynamic Azure AD device groups.)
  • Remove-AutoPilotImportedDevice, which removes the status objects once the processing is complete.

Notice that there is no function to remove the added devices. Just like in the Intune portal, there’s no way to do this yet – you can remove the device via the Microsoft Store for Business, but you’ll still see it in Intune. That’s still being worked on.

As always, the PowerShell module is provided as an example, provided as-is with no warranty or support, and could easily have bugs. See the Intune Graph API documentation for more details on the REST calls being leveraged and the PowerShell Intune Samples on GitHub to interact with Intune via the Graph API.

Would you like to read more about Microsoft Windows-related articles? If so, we invite you to take a look at our other tech topics before you leave!

Use our Internet marketing service to help you rank on the first page of SERP.

Subscribe To Our Newsletter

Get updates and learn from the best