Hello,
Thanks to the quick and helpful responses I have been getting here I have been able to make a CSOM PS script to pull data from an external list and save it as a CSV file. Data is getting pulled regularly and all was well until
I had to start pulling the external list’s ID number. I’ve added that to my powershelgl script and I seem to be getting almost all of the ID numbers of the 1500+ items except for a few items that give me either a ‘5’ or ‘blank’ I cannot explain this because when I view the list itself, I am able to see all the ID numbers.
Also, as a test I modified my script to pull only the ID numbers to only get the same results. I’m hoping someone can shed some light on this issue I am facing. Below is the script I am using where the outcome is a CSV file that
gives me the ID numbers and the Title of each item from the external list.
Function Get-SPClientList {
param (
$uri,
$list
)
$cSharp = @"
using System;
using System.Collections.Generic;
using Microsoft.SharePoint.Client;
namespace SPClient
{
public class SharePointList
{
public static ListItemCollection GetList()
{
ClientContext clientContext = new ClientContext(`"$uri`");
List list = clientContext.Web.Lists.GetByTitle(`"$list`");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View/>";
ListItemCollection listItems = list.GetItems(camlQuery);
clientContext.Load(list);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
return listItems;
}
}
}
"@
$assemblies = @(
"$PSSCriptRoot\Microsoft.SharePoint.Client.dll",
"$PSSCriptRoot\Microsoft.SharePoint.Client.Runtime.dll"
"System.Core"
)
Add-Type -TypeDefinition $cSharp -ReferencedAssemblies $assemblies
$items = [SPClient.SharepointList]::GetList()
$out = @()
foreach ($item in $items) {
$obj = new-object psobject
foreach ($i in $item.FieldValues)
{
$keys = @()
$values = @()
foreach ($key in $i.keys) {$keys += $key}
foreach ($value in $i.values) {$values += $value}
for ($i = 0; $i -lt $keys.count-1; $i++)
{
if(($keys[$i] -eq “ID”) -or ($keys[$i] -eq “Title”))
{
$obj | Add-Member -MemberType noteproperty -Name $keys[$i] -Value $values[$i]
}
}
}
$out += $obj
}
$out | Export-CSV "D:\Install\scripts\ExternalList.csv" -NoTypeInformation
####This is the end#####
}
Get-SPClientList('http://externalsite/sites/site1/', 'ExternalList')









