Reputation: 464
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
Upvotes: 2
Views: 20764
Reputation: 201672
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.
Upvotes: 1