Below is a sample PowerShell script showing how to update a registered device’s extension attribute. The sample uses extensionAttriubte3. You can easily swap this out to a different one. Refer to the Update Device documentation for more info.

Import-Module Microsoft.Graph.Identity.DirectoryManagement
# Log in with the correct scope
Connect-MgGraph -Scopes "Directory.AccessAsUser.All"

$DeviceId = "<Device ObjectId>"
$params = @{
   "extensionAttributes" = @{
      "extensionAttribute3" = "hello2"
   }
}
# Update Device
Update-MgDevice  -DeviceId $DeviceId  -BodyParameter ($params | ConvertTo-Json)

<# 
The following technique to create json payload also works.  Thanks to my colleague Will Fiddes for the idea
$json = '{ "extensionAttributes": { "extensionAttribute1": "BYOD-Device" } }'
Update-MgDevice -DeviceId $DeviceId -BodyParameter $json
#>

# Query Device
Get-MgDeviceById -DeviceId $DeviceId

Note: The above device update operation requires the signed in user to be in either the Intune Administrator role or Global Administrator role.

5 Thoughts to “How to use Microsoft Graph SDK for PowerShell to update a registered Device’s Extension Attribute”

  1. Rahol

    Hello,

    Thank you for your script, if i understand thats work only with devices enrolled into Intune.

    The devices marked as only Hybrid Azure AD Join will not be updated by these script ?

    Thanks for confirmation

    1. Bac Hoang [MSFT]

      The script should work for hybrid joined devices

  2. William

    How about if need to update an extenssion attributes on bulk Azure AD device from CSV file

    1. Bac Hoang [MSFT]

      Hi William,
      You would have to do some preprocessing to parse through the data in the csv file in order to build the correct MS Graph request body and then send out the individual requests. Also you can look into batching per https://learn.microsoft.com/en-us/graph/json-batching to see if this helps

      1. William

        I have modified the script to update an extension attributes on multiple Azure AD devices from a CSV file and it’s work.

        # Update Device
        $devices = Import-Csv -path c:\AADDeviceObjectID.csv
        $devices.id
        ForEach ($device in $devices) {

        Update-MgDevice -DeviceId $device.id -BodyParameter ($params | ConvertTo-Json)
        }

Leave a Reply to Bac Hoang [MSFT] Cancel reply