On SharePoint 2013, I am trying to get list items, with client-side SharePoint PowerShell. Even for field Id or Title, I encounter this error: The collection has not been initialized. I don't know how to include fields. I find many exemples in C# or JavaScript but none in client side powershell.
Here is my code (it returns correctly the number of items):
Function New-Context([String]$WebUrl) {
$context = New-Object Microsoft.SharePoint.Client.ClientContext($WebUrl)
$context.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$context
}
Function Get-List([Microsoft.SharePoint.Client.ClientContext]$Context, [String]$ListTitle) {
$list = $context.Web.Lists.GetByTitle($ListTitle)
$context.Load($list)
$context.ExecuteQuery()
$list
}
$context = New-Context -WebUrl "http://mysharepoint.com/sites/qp"
$list = Get-List -Context $context -ListTitle "QP-Configuration"
$query = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()
$items = $list.GetItems($query)
$context.Load($items)
$context.ExecuteQuery()
$items.Count
$items[0]
foreach($item in $items)
{
$item.Id
}
$context.Dispose()