Made a change to an existing PowerShell script, then ran into this error: Unable to index into an object of type Microsoft.SharePoint.SPList
If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) { Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell } $web = Get-SPWeb "http://sharepointed.com/sitename" $listTask = $web.Lists["My List"] $sItem = $listTask.GetItemById(9) $title = $listTask["Title"]
In the script, you will notice that I’m trying to capture the title of the item. The above script wasn’t working because I failed work with this list item, instead I was trying to work with the list object.
Correct script:
If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) { Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell } $web = Get-SPWeb "http://sharepointed.com/sitename" $listTask = $web.Lists["My List"] $sItem = $listTask.GetItemById(9) $title = $sItem["Title"]