SharePoint Online: Export User Information List using PowerShell

Requirement: Export User Information List in SharePoint Online

User Information List in SharePoint Online stores the information about users. It captures user metadata 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.

How to Export User Information List to Excel from SharePoint Online?

Are you looking for a way to export the user information list from SharePoint Online? In this guide, we’ll show you how to do just that with easy-to-follow steps! You’ll have your user data quickly exported and ready to work with in Excel. The exported spreadsheet will include the user’s display name, email address and last logon date, etc.

  • To get started, open the Microsoft Excel desktop application
  • Click on the “Data” tab >> Get Data >> From Other Sources > SharePoint List (In some versions, it is under: Data >> New Query >> From other sources >> SharePoint List)export user information list sharepoint online
  • Enter your SharePoint Online site URL and click on OKuser information list sharepoint online
  • Click on “Microsoft Account”>> Click on the “Sign in” button to log in to SharePoint Online and then click on “Connect”sharepoint online export user information list to excel
  • This will open a window with all the available lists on your site. Scroll down and select the User Information List and click on “Load”.user information list sharepoint

This loads the data from the user information list to Excel and you can view and analyze the data.

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 the 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 user data from the user information list. 

#Connect to SharePoint Online
Connect-SPOService -Url https://crescent-admin.sharepoint.com

#Export User Info
Export-SPOUserInfo -LoginName [email protected] -site https://crescent.sharepoint.com/sites/marketing -OutputFolder "C:\Temp"

PnP PowerShell to Export User Data from User Information List

We have an equivalent PnP PowerShell cmdlet Export-PnPUserInfo to export user data from the user information list:

#Config Variables
$SiteURL = "https://crescent.sharepoint.com/sites/Retail"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive

Export-PnPUserInfo -LoginName [email protected] -Site $SiteURL | ConvertTo-Csv | Out-File C:\Temp\Userinfo.csv

Here is another post for SharePoint On-premises: How to Export User Information List in SharePoint?

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

Your email address will not be published.