Articles about European Sharepoint Hosting Service
SharePoint 2013 Hosting – HostForLIFE.eu :: Fetch All The Users And Their User Profile Properties Using PnP PowerShell
With so many companies preferring Microsoft 365 as the platform for their internal collaboration and other uses, it becomes very important to check which users are present and fetch their profile properties from SharePoint.
To achieve this we will use PnP PowerShell and AzureAD PowerShell Modules to fetch all the users and extract their user profile properties from SharePoint
Prerequisites
If we are using Window 10 or we have PowerShellGet then we can run the below commands to install PnP PowerShell and AzuerAD Modules
Install PnP PowerShell Module,
1 |
Install-Module SharePointPnPPowerShellOnline -Scope CurrentUser |
Install AzureAD Module
1 |
Install-Module AzureAD -Scope CurrentUser |
PowerShell Script
Once we have installed all the dependencies we will now do two operations:
- Connect to Azure AD and fetch all the users present in the Azure AD
- Iterate through all the users and fetch user profile properties for each user
To run the below PowerShell script we should have admin access to fetch all the users and fetch the user profile properties.
Two inputs will be required:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
Admin Site Collection URL - Provide SharePoint Online Admin Site Collection URL in the format https://<<domain>>-admin.sharepoint.com File Path - Please provide the file path along with the file name with .csv as the file extension eg:- E:\Scripts\AllUsersProfiles.csv $AdminSiteCollectionUrl = Read-Host "Please enter admin Site Collection URL" $FilePath = Read-Host "Please enter the file path along with filename.csv" $Cred = Get-Credential Connect-AzureAD -Credential $Cred $AzureADUsers = Get-AzureADUser -All:$True Connect-PnPOnline $AdminSiteCollectionUrl -Credentials $Cred $UserProfileData = @() ForEach($AzureADUser in $AzureADUsers) { $UserDetail = Get-PnPUserProfileProperty -Account $AzureADUser.UserPrincipalName $EachUserProfile = New-Object PSObject ForEach($Key in $UserDetail.UserProfileProperties.Keys) { $EachUserProfile | Add-Member NoteProperty $Key($UserDetail.UserProfileProperties[$Key]) } $UserProfileData += $EachUserProfile } $UserProfileData | Export-Csv -Path $FilePath -NoTypeInformation |
Outcome
A CSV file with all the user profile properties will be generated in the specified path. We can use this file for additional analytics.
Print article | This entry was posted by Peter on June 9, 2020 at 9:06 am, and is filed under European SharePoint 2013 Hosting. Follow any responses to this post through RSS 2.0. Both comments and pings are currently closed. |