Collecting all user profile properties using PnP PowerShell

Collecting all user profile properties using PnP PowerShell

By:

Date:

Most of my regular readers will already know that I like the PnP PowerShell commands projects.

Today I’m trying to collect current values of User profiles in Office 365. I first tried using SharePoint search but it is impossible to collect any data real time.

So in my second attempt I started using the PnP PowerShell.

I start setting some variables that will help collecting credential details

 

$tenantname = "mytenant"
$tenantadminurl = "https:/ /$tenantname-admin.sharepoint.com"
$siteUrl = "https:/ /$tenantname.sharepoint.com"
$username = "pieterveenstra@$tenantname.onmicrosoft.com"
$cred = Get-Credential -UserName $username -Message "Please supply password"
GetCredentials

I first will try and collect all my users on the system.

Connect-SPOService -Url "$tenantadminurl" -Credential $cred
$users = Get-SPOUser -Site $siteUrl

Then I’m using the Get-SPOUserProfileProperty command to collect all the user profile properties:

Connect-SPOnline $siteUrl -Credentials $cred

foreach ($user in $users)
{
Write-Host -ForegroundColor Yellow $user.LoginName
$profile = Get-SPOUserProfileProperty -Account $user.LoginName
Write-Host $profile.UserProfileProperties
}

This now gives me a full overview of all my user profile properties.

The full script

Clear-Host

$tenantname = "mytenant"
$username = "pieterveenstra@$tenantname.onmicrosoft.com"

$cred = Get-Credential -UserName $username -Message "Please supply password"

Connect-SPOService -Url "$tenantadminurl " -Credential $cred
$users = Get-SPOUser -Site $siteUrl
Connect-SPOnline $siteUrl -Credentials $cred

foreach ($user in $users)
{
Write-Host -ForegroundColor Yellow $user.LoginName
$profile = Get-SPOUserProfileProperty -Account $user.LoginName
Write-Host $profile.UserProfileProperties
}

Is your business still running on paper trails, sprawling Excel files, or ageing Access databases? There’s a better way — and I can show you exactly what it looks like. I’m the Technical Director of Vantage 365, a Microsoft solutions consultancy working with clients across the UK, the Netherlands, and worldwide. For over 30 years I’ve been turning messy, manual business processes into clean, automated systems that save time, reduce errors, and give teams the visibility they need to make better decisions. SharePains is not just any blog run by a Microsoft MVP. Have you ever used Try-Catch in Power Automate? The original post about Try-Catch in Power Automate can still be found on this site, https://staging.sharepains.com/2018/02/07/try-catch-finally-in-power-automate-flow/ Or have you ever used the Pieter’s method to avoid variables and speed up your flows? https://staging.sharepains.com/2020/03/11/pieters-method-for-advanced-in-flows/ You can contact me using contact@staging.sharepains.com

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.