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
}

 

Advertisements