2

I'm trying to use the script below to get some data out from a list. I'm using it for my Sp 2007 and it workd but when using it under SP 2010 i get the error. Any ideas. THanks

Cannot index into a null array.
At \64284ccd-adc9-4ae4-be4c-0fcd744be7c1.ps1:12 char:19
+     Title = $item[ <<<< "Title"]
    + CategoryInfo          : InvalidOperation: (Title:String) [], RuntimeException
    + FullyQualifiedErrorId : NullArray



[System.reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$site    =     new-object Microsoft.SharePoint.SPSite("http://mysite/Intranet")                                                       

$web     = $site.rootweb                                                                                               
$list    =    $web.Lists["Comms"]

$Responses = @()


foreach ($item in $list.items) {
#$list.Items | foreach {
$obj = New-Object PSObject -Property @{
    Title = $item["Title"]

}
$obj |select-object Title
$Responses += $obj
}
Write-Host $Response
0

1 Answer 1

1

Debugging PowerShell generally involves inspecting the values of intermediate variables. In this case, it is obvious from the error that $item is null. This probably means that $list.items is $null. This means either the items property is null or more likely that $list is null. You can check if $list is null like so: $list -eq $null. If it is null, makes sure the $web variable isn't null. If it isn't then enumerate the web lists like so $web.Lists to see if "Comms" shows up.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.