Forum Discussion
DaveG1
Aug 30, 2021Copper Contributor
Get specific SharePoint user profile property with PowerShell
Hello everybody, I'm trying to get a specific, custom user profile property from all our users profiles to make an evaluation. I tried PnP-Powershell but the needed property is not shown. Is ...
RonLevy
Sep 29, 2023Brass Contributor
Hi DaveG1,
I just came along your post. It is a little late but this might help others.
You can use Get-PnPUserProfileProperty but need to connect to admin site with proper permissions to get it to work. (using ACS)
So, navigate to appinv.aspx of your admin site and add this:
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl" />
<AppPermissionRequest Scope="http://sharepoint/social/tenant" Right="Read" />
</AppPermissionRequests>You need to pride your Application-ID and trust the entry.
Then you can connect.
Connect-PnPOnline -Url $adminUrl -ClientId $clientId -ClientSecret $secretValue
ClientID must be the Application-ID of related App-Registration and ClientSecret the secret of related App-Registration.
API-Permission of related App-Registration must have
Then you can get your custom property:
$UserAccount = "i:0#.f|membership|$($user.UserPrincipalName)"
$UserProfile = Get-PnPUserProfileProperty -Account $UserAccount
$currentSBU = $UserProfile.UserProfileProperties["SBU"]
I am using this setup because my script is running in an Azure Runbook.
Cheers, Ronny