Whether you use SharePoint online or server?
For SharePoint online, run following PowerShell in the SharePoint Online Management Shell:
#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"
##Variables for Processing
$SiteUrl = "https://tenant.sharepoint.com/sites/emilytest"
$ListName= "list"
$ExportFile ="c:\ListItems.csv"
#Get Credentials to connect
$Cred = Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Ctx.Credentials = $Credentials
#Get the List
$List = $Ctx.web.Lists.GetByTitle($ListName)
#Get All List Items
$Query = New-Object Microsoft.SharePoint.Client.CamlQuery
$ListItems = $List.GetItems($Query)
$FieldColl = $List.Fields
$Ctx.Load($ListItems)
$Ctx.Load($FieldColl)
$Ctx.ExecuteQuery()
#Array to Hold List Items
$ListItemCollection = @()
#Fetch each list item value to export to excel
Foreach($Item in $ListItems)
{
$ExportItem = New-Object PSObject
Foreach($Field in $FieldColl)
{
if($NULL -ne $Item[$Field.InternalName])
{
#Expand the value of Person or Lookup fields
$FieldType = $Item[$Field.InternalName].GetType().name
if (($FieldType -eq "FieldLookupValue") -or ($FieldType -eq "FieldUserValue"))
{
$FieldValue = $Item[$Field.InternalName].LookupValue
}
else
{
$FieldValue = $Item[$Field.InternalName]
}
}
$ExportItem | Add-Member -MemberType NoteProperty -name $Field.InternalName -value $FieldValue
}
#Add the object with above properties to the Array
$ListItemCollection += $ExportItem
}
#Export the result Array to CSV file
$ListItemCollection | Export-CSV $ExportFile -NoTypeInformation
Write-host "List data Exported to CSV file successfully!"
For SharePoint server, run following PowerShell in the SharePoint Server Management Shell:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Variables
$SiteUrl="https://webapplication/sites/testsite"
$ListName="list"
$OutPutFile = "C:\ListData.csv"
#Get Web and List
$web = Get-SPWeb $SiteUrl
$List = $Web.Lists[$ListName]
Write-host "Total Number of Items Found:"$List.Itemcount
#Array to Hold Result - PSObjects
$ListItemCollection = @()
#Get All List items
$List.Items | ForEach {
write-host "Processing Item ID:"$_["ID"]
$ExportItem = New-Object PSObject
#Get Each field
foreach($Field in $_.Fields)
{
$ExportItem | Add-Member -MemberType NoteProperty -name $Field.InternalName -value $_[$Field.InternalName]
}
#Add the object with property to an Array
$ListItemCollection += $ExportItem
}
#Export the result Array to CSV file
$ListItemCollection | Export-CSV $OutPutFile -NoTypeInformation
Write-host -f Green "List '$ListName' Exported to $($OutputFile) for site $($SiteURL)"
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.