2

I keep getting this error messeage when I try look at a ViewCollection from a list

format-default : The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested. + CategoryInfo : NotSpecified: (:) [format-default], CollectionNotInitializedException + FullyQualifiedErrorId : Microsoft.SharePoint.Client.CollectionNotInitializedException,Microsoft.PowerShell.Commands.FormatDefaultCommand

I believe my $list.views object is not being initialized. I have tried the following

$ctx.Load($list)
$ctx.Load($list.views)
$ctx.Load($list, 'Views')     <-- incorrect syntax  and other variations 

I know I need a SP.ClientObject to load into the context before running my ExecuteQuery but the only examples I see are c# code which uses lambda Expressions to load in properties explicitly but I am unaware of how to do the same thing in powershell

1 Answer 1

2

Use $ClientContext.Load($list.Views)syntax in PowerShell to load Views collection, for example:

$list = $Context.Web.Lists.GetByTitle($ListTitle)
$Context.Load($list)
$Context.Load($list.Views)
$Context.ExecuteQuery()
if ($list.IsObjectPropertyInstantiated('Views') -eq $true)
{
   Write-Host "Views collection has been loaded"
}
4
  • Have you tested this out? From what I saw online you practically had to write C# code inside of powershell. I could have Sworn I have tried $Context.Load($list.Views) before and it still didn't load it.
    – McFrank
    Oct 27, 2014 at 20:09
  • Yep, the specified code works for me just fine, there is no need to inject c# code Oct 27, 2014 at 20:12
  • cool Ill give it a try later today when I get off of work
    – McFrank
    Oct 27, 2014 at 20:13
  • 1
    of course it works, it's Vadim's code, +1
    – grisha
    May 16, 2015 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.