$SiteUrl = " yoursiteURL" $ListName="yourlistname" $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!"