Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights 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?

    Reply
  • 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

    Reply
    • I’m also having the same

      Reply
      • There is a bug for Set-PnPUserProfileProperty, see the following : https://github.com/pnp/powershell/issues/277
        No ETA yet as to when it will be fixed. You can loging using the -AppId and -AppSecret instead to bypass this

        Reply
        • 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?

          Reply
          • 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!

            Reply
  • 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?

    Reply
  • 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?

    Reply
  • 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.

    Reply
  • 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”?

    Reply
    • 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.”

      Reply
  • 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?

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

      Reply
    • 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”

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

      Reply
  • 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?

    Reply

Leave a Reply

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