Share via


Export SharePoint Online User Profile Information Using PowerShell - CSOM

 


 Export SharePoint Online User Profile Information PowerShell - CSOM


Introduction

This Wiki article shows step by step procedure to export SharePoint Online User Profile Information. If you are looking SharePoint 2010 please refer this script in TechNet Gallery Export SharePoint User Profile


Prerequisites

You need Microsoft.SharePoint.Client.UserProfiles.dll to execute this script.

  1. PowerShell
  2. SharePoint Server 2013 Client Components SDK
  3. Supported OS: Windows 7 Service Pack 1, Windows 8, Windows Server 2008 R2
  4. Download Link: http://www.microsoft.com/en-us/download/details.aspx?id=35585

Procedure

  1. Install SharePoint Client Components - Mostly 64 bit.sharepointclientcomponents_x64.msi
  2. Ensure you have DLLs downloaded to the location 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI'. Note: The hive value may change 15 or 16.
  3. Once you have installed the SharePoint Client Components the below DLLs will be available.
    • Microsoft.Office.Client.Education.dll
    • Microsoft.Office.Client.Policy.dll
    • Microsoft.Office.Client.TranslationServices.dll
    • Microsoft.SharePoint.Client.dll
    • Microsoft.SharePoint.Client.DocumentManagement.dll
    • Microsoft.SharePoint.Client.Publishing.dll
    • Microsoft.SharePoint.Client.Runtime.dll
    • Microsoft.SharePoint.Client.Search.Applications.dll
    • Microsoft.SharePoint.Client.Search.dll
    • Microsoft.SharePoint.Client.Taxonomy.dll
    • Microsoft.SharePoint.Client.UserProfiles.dll
    • Microsoft.SharePoint.Client.WorkflowServices.dll.
  4. We will use only Microsoft.SharePoint.Client.UserProfiles.dll

Code

#Import the required DLL
Import-Module 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll'

#Mysite URL
$site = 'https://Domain-my.sharepoint.com/'

#Admin User Principal Name
$admin = 'Admin@Domain.OnMicrosoft.Com'

#Get Password as secure String
$password = Read-Host 'Enter Password' -AsSecureString

#Get the Client Context and Bind the Site Collection
$context = New-Object Microsoft.SharePoint.Client.ClientContext($site)

#Authenticate
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($admin , $password)
$context.Credentials = $credentials

#Fetch the users in Site Collection
$users = $context.Web.SiteUsers
$context.Load($users)
$context.ExecuteQuery()

#Create an Object [People Manager] to retrieve profile information
$people = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($context)
$collection = @()
Foreach($user in $users)
{
                   
    $userprofile = $people.GetPropertiesFor($user.LoginName)
    $context.Load($userprofile)
    $context.ExecuteQuery()
    if($userprofile.Email -ne $null)
    {
        $upp = $userprofile.UserProfileProperties

        $profileData = "" | Select "FirstName" , "LastName" , "WorkEmail" , "Title" , "Responsibility"
        $profileData.FirstName = $upp.FirstName
        $profileData.LastName = $upp.LastName
        $profileData.WorkEmail = $upp.WorkEmail
        $profileData.Responsibility = $upp.'SPS-Responsibility'
        $collection += $profileData

    }
}
$collection | Export-Csv C:\Temp\SPO-UserInformation.csv -NoTypeInformation -Encoding UTF8

Output


Download Code

https://gallery.technet.microsoft.com/scriptcenter/Export-SharePoint-User-5e3f6a1a/file/132345/1/Export_SPOUserProfiles.7z