Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

$web gives me the title of the website $list is not giving me any and therefore item add/update i m doing is failing. What is wrong? The code works in dev area. btw, I am running with full rights on the app server.

if((Get-PSSnapin | Where {$_.Name -eq “Microsoft.SharePoint.PowerShell”}) -eq $null)
{
    Add-PSSnapin Microsoft.SharePoint.PowerShell
}

$web = Get-SPWeb "http://intranet.Rubbermaid.com/Sales" 
$ListName = "2012SalesReport1Q"
$list = $web.Lists[$ListName]

write-host $web
write-host $list
write-host " - - - - Starting Process - - - - "

Rest of the code...

share|improve this question
    
basically $web.Lists[$ListName] not working. I even tried $web.Lists.TryGetList($ListName) and still the same. But they work fine in dev area. –  Angie Heimerlake Jun 7 '12 at 18:23
    
I tried almost all the list on that site collection and none seem to answer my call. so what to do? –  Angie Heimerlake Jun 7 '12 at 18:31

1 Answer 1

up vote 2 down vote accepted

This means $web.Lists[$ListName] returns null. The reason is that you should pass title, not list root folder name or list url, to the SPWeb.Lists[string] indexer. For example:

$list = $web.Lists["My precious list"]

I assume 2012SalesReport1Q in your code refers to the list root folder name, i.e. it has address http://portal/Lists/2012SalesReport1Q. In this case, to get the list object, you should use SPWeb.GetListFromWebPartPageUrl method (a bit long, yep :)..):

$list = $web.GetListFromWebPartPageUrl("http://portal/Lists/2012SalesReport1Q/AllItems.aspx")

Notice we have to pass full url of the list view page, including "AllItems.aspx", otherwise it won't work.

share|improve this answer
    
The list name is "2012SalesReport1Q" and there are no folders under this list. so what to do? –  Angie Heimerlake Jun 7 '12 at 18:36
    
Go to the list view page, copy the actual url of the page, and use GetListFromWebPartPageUrl, as I've described above. –  Andrey Markeev Jun 7 '12 at 18:38
    
Found the issue. You CAN NOT USE INTERNAL NAME for the list (if internal name is different than external Name) in this code so it should be $ListName = "External Name" $List = $web.Lists[$ListName] This works now. Thanks Andrey –  Angie Heimerlake Jun 7 '12 at 18:40
    
That is what I meant. What you call "External name" refers to SPList.Title property, and what you call "Internal name", is actually the list root folder name: SPList.RootFolder.Name. –  Andrey Markeev Jun 7 '12 at 18:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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