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]
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]