SharePoint Online: Export User Information List using PowerShell

Requirement: Export User Information List in SharePoint Online

User Information List in SharePoint Online stores information about a user by having some metadata set up for the user such as User Picture, Email, DisplayName, LoginName etc. When we grant permissions to a user, they are added automatically to the hidden User Information list. SharePoint retrieves user related metadata for fields such as Created By,  Last modified, etc from the User Information List.

PowerShell to Export User Information List in SharePoint Online
This PowerShell script exports all user information to a CSV file from the user information list of any SharePoint Online site collection.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Parameters
$SiteURL="https://crescent.sharepoint.com/sites/marketing"
$CSVPath = "C:\Temp\UserInfo.csv"

#Get Credentials to connect
$Cred= Get-Credential

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

    #Get the User Information List
    $List=$Ctx.Web.SiteUserInfoList
    $FieldColl = $List.Fields
    $Ctx.Load($List)
    $Ctx.Load($FieldColl)
    $Ctx.ExecuteQuery()
 
    #Get All Items from User Information List
    $ListItems = $List.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
    $Ctx.Load($ListItems)
    $Ctx.ExecuteQuery()

    #Array to Hold Result - PSObjects
    $ListItemCollection = @()
  
    #Fetch each list item value to export to excel
    ForEach($Item in $ListItems)
    {
        $ExportItem = New-Object PSObject 
        ForEach($Field in $FieldColl)
        {
            $ExportItem | Add-Member -MemberType NoteProperty -name $Field.InternalName -value $Item[$Field.InternalName]   
        }  
        #Add the object with property to an Array
        $ListItemCollection += $ExportItem
    }
    #Export data to CSV File
    $ListItemCollection | Export-Csv -Path $CSVPath -NoTypeInformation -Force

    Write-host "User Information List has been Exported to CSV!'" -f Green
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}
This script generates below CSV file (I've removed some of the columns from the CSV, BTW!)
export user information list sharepoint online


Export User data from User Information List using SharePoint Online Management Shell:
SharePoint Online Management Shell has a cmdlet Export-SPOUserInfo to export a user data from user information list. 
#Connect to SharePoint Online
Connect-SPOService -Url https://crescent-admin.sharepoint.com

#Export User Info
Export-SPOUserInfo -LoginName salaudeen@crescent.com -site https://crescent.sharepoint.com/sites/marketing -OutputFolder "C:\Temp"

Here is my another post for SharePoint On-premises: How to Export User Information List in SharePoint?
SharePoint Online: Export User Information List using PowerShell SharePoint Online: Export User Information List using PowerShell Reviewed by Salaudeen Rajack on August 17, 2018 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.