Working with list items

Apr 1, 2014 at 4:56 PM
This is some impressive work!

Are there any functions implemented for working with list items yet? I have found the Add-ListItems that imports data from a CSV, but I would like to retreive list items as well.

I am currently working on a Get-ListItems, but I just want to make sure that it has not already been implemented...
Coordinator
Apr 15, 2014 at 7:44 AM
Get-ListItems is not yet implemented, if you have it, please update the code, so it can become part of the project.

Jeffrey
May 20, 2014 at 12:02 AM
Hi Jeffrey and Kalle, I'm very rusty on PS and .NET code, so I preface this by saying I'm not sure I'll be much help in advancing the code.

With that embarrassing admission, I'd like to inquire whether there's been any further advancements on the Get-ListItems front? I have a sizeable SharePoint installation where I have a few lists that have exceeded 20K records, and I'm struggling now to find a way to read and perhaps even update the data in those lists (without screwing around so much with List Views).

Is there any chance either of you have made progress on the List Item access front?

Thanks so much for any help or clues you might be able to provide.
Jul 30, 2014 at 7:54 PM
I see other users are also welcoming this feature, I will be starting on that, hope to have an update soon.

Thanks for the feedback.
Jul 31, 2014 at 6:32 AM
I would like this get-Listitem feature too.

Maybe you can look at this code to get started:
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl) # Create new Object in SP Client context
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $SecurePassword) # Connect to SPO with credentials
$List = $Ctx.Web.Lists.GetByTitle($listname) # Get list 
$Query = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery($queryitemlimit) # Query for maximum number of rows
$Items = $List.GetItems($Query) 
$Ctx.Load($Items)
$Ctx.ExecuteQuery()
Oct 10, 2014 at 6:58 PM
Ronald's code looks good - it's a pattern we tried in one of our scripts.

Here's another pattern we tried for a different scenario:
$siteUrl = "https://web.address.com/sites/sitename/"
$List = "Name of SP List"

$GLOBAL:Context = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$GLOBAL:Web = $GLOBAL:Context.Web
$GLOBAL:Context.Load($GLOBAL:Web)
$SPList = $GLOBAL:Web.Lists.GetByTitle($List)
$GLOBAL:Context.Load($SPList)
$GLOBAL:Context.ExecuteQuery()

For ($i=0; $i -le $SPList.ItemCount; $i++)
{
$ListItem = $SPList.GetItemById($i)
$GLOBAL:Context.Load($ListItem)
Try
{
    $GLOBAL:Context.ExecuteQuery()
}
Catch
{
    $i++
    $ListItem = $SPList.GetItemById($i)
    $GLOBAL:Context.Load($ListItem)
    $GLOBAL:Context.ExecuteQuery()
}
Finally
{
    #Return item here and do something with it.
    Write-Output "List Item " $i " = " $ListItem["Title"]
}
}

We came up with an even more complex looping pattern to address the fact that in some of our lists, we've deleted records such that ItemCount < [largest ID of last item in the list].