Updating User properties using GraphAPI

USE Graph API to update User properties in office 365 using PowerShell REST Patch Method

Links to my old post on this series are given below.

In this post, we will use the PATCH method to update a user in office 365.

Following attributes can be used to update a user:


$aboutMe, $interests, $postalCode,
$accountEnabled, $jobTitle, $preferredLanguage,
$birthday, $mailNickname, $responsibilities,
$city, $mobilePhone, $schools,
$country, $mySite, $skills,
$department, $officeLocation, $state,
$displayName, $onPremisesImmutableId,  $streetAddress,
$givenName, $passwordPolicies, $surname,
$hireDate, $passwordProfile, $usageLocation,
$userType, $pastProjects, $userPrincipalName,

Requirements: 


Service account should have following permissions
  • Permission: User.ReadWrite.All, Directory.ReadWrite.All
  • Role: At least "User management administrator"
PATCH method is the same as the POST method, we need to supply the JSON in the body.

Sample JSON:


{
    "givenName":'Test',
    "surname":'User',
    "city":'Noida',
    "country":'IN',
    "department":'IT',
    "jobTitle":'System Admin',
    "officeLocation":'Sector 126',
    "mobilePhone":'9999999999'
}


Submit Patch Request: 


To update user properties we need to submit patch request at URL
"/users/{id | userPrincipalName}" 

$URI="https://graph.microsoft.com/v1.0/users/" + $upn
$Results = Invoke-RestMethod -Headers $Header -Uri $Uri -Method PATCH -Body $JSON


Note: How to fetch the authorization token and prepare header has been discussed in the last post.

Full supported PowerShell code for this section can be downloaded from the GitHub repository.
This completes my post on updating user properties using graph API, please feel free to leave your feedback in the comment section.

Comments