Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience to help others, through the real-world articles!

18 thoughts on “SharePoint Online: Sync User Profile Property from Azure AD using PowerShell

  • I’m having an issue with line 29 of the second script; when storing the value of the expanded property in the variable it always comeback that it doesn’t exist, whatever the property I try to select ;
    $ADUserPropertyValue = $User | Select -ExpandProperty $ADPropertyName
    Anyone having the same problem?

  • I am getting error while doing it for all users – Set-PnPUserProfileProperty : This operation requires you to be managing your own data or have administrator privileges. I am sharepoint administrator already

    • I’m also having the same

      • There is a bug for Set-PnPUserProfileProperty, see the following :
        No ETA yet as to when it will be fixed. You can loging using the -AppId and -AppSecret instead to bypass this

        • Appid and appsecret are no longer an option for connect-pnponline.
          generally -interactive seems to fix most problems so I updated my script testing for just one user and i’m still getting the permission error despite interactive login using Global Admin account to login.
          I need to change a number of mappings any idea how to get around the permissions issue?

          • After digging through the Github a bit I was able to make this script work by changing the connect-pnplogin to the following;
            Connect-PnPOnline -S -Url $AdminSiteURL -Credentials $cred
            I believe the -S flag being the most critical. Weird because most times if i’m not using -interactive now the pnp modules fail but at least this works!

  • Running this as a global admin and sharepoint admin and receive the following;

    Set-PnPUserProfileProperty : Access denied. You do not have permission to perform this action or access this resource.

    Any ideas why this would be the case?

  • Salaudeen, I tried the first script and ran into a few problems. First, it looks like it needs t be “mobile” and not “MobilePhone”. I made that change and got a bit further but then I get an error “Error Synching User Profile Property! Exception calling “.ctor” with “2” argument(s): “The ‘username’ argument cannot be null.
    Parameter name: username”. I am NOT a wiz with Powershell or any of the rest of this. Can you point me in right direction?

  • Thanks Salaudeen, Good article. I’m hoping this has moved me forward very quickly on a bit of project work, with the introduction of a few improvements to allow for script #2 to update multiple properties per user account.

  • Can I use this script to sync “Country or Region” from Azure AD to SharePoint user profile property? Just change these values?
    $ADPropertyName = “Country”
    $SPOPropertyName = “Country”

    second question. I assumed I have to create a custom managed property in SharePoint called “Country”?

    • Script works great for all users until it ran into an error on a user that doesn’t have user profile. The script stop after it. How do I modify the script to ignore the error and continue to the next user?

      error”Error Updating User Profile Property! Cannot index into a null array.”

  • Hi,
    Can a custom property in On-Premise AD be synced to Azure AD and then synced to a Custom User profile property in SPO, using this approach? Or does it only work for standard properties of AD?

    • Yes! It works for any Azure AD Properties, Including Custom user profile properties from AD!

    • Great post Salaudeen!

      So to utilise extended fields from AD/AAD, would this mean it’s just a case of defining the variables for the customer fields? and then a foreach for each of the custom values?

      $ADPropertyName = “MyCustomValue”
      $SPOPropertyName = “MyCustomValue”

    • Yes, That’s right! Also make sure your extended property is mapped from AD to AAD in AD Sync tool.

  • Hi, Does it work for a custom property in On-Premise AD which is synced to Azure AD ?
    In another words, If we create a custom user profile property in User profile application within SPO, with the above script can we sync any corresponding custom attribute from Local Ad to Azure AD to the Custom User Profile property?


Leave a Reply

Your email address will not be published. Required fields are marked *