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

[code lang=text]
$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”
[/code]

GetCredentials

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

[code lang=text]
Connect-SPOService -Url “$tenantadminurl” -Credential $cred
$users = Get-SPOUser -Site $siteUrl
[/code]

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

[code lang=text]
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
}
[/code]

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

The full script

[code lang=text]
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
}
[/code]

Avatar for Pieter Veenstra

By Pieter Veenstra

Business Applications and Office Apps & Services Microsoft MVP working as a Microsoft Productivity Principal Consultant at HybrIT Services. You can contact me using contact@veenstra.me.uk.

Leave a Reply

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

%d bloggers like this: