Dienstag, 6. September 2011

Add Circulation List to SharePoint 2010 Web using PowerShell


PowerShell is great. I'm working on scripting a whole deployment process with PowerShell. Yesterday I got stuck in a problem that costs me about 6 hours of my life. 
If you want to add a list to a SPWeb you will find in a lot of blogs this description:

$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::Circulation
$spweb.Lists.Add(MyCirculation“,"Description",$listTemplate)

And guess what? It works fine for a lot of list templates. But then I tried with “Circulation” and I got this error:


Exception calling “Add” with 3 argument(s) “Invalid list template.”

I tried a lot And I found out that I need to use this Add Method:
http://msdn.microsoft.com/en-us/library/ms448694.aspx

So I tried with this code:

$listTemplate = [Microsoft.SharePoint.SPListTemplateType]:: Circulation
$spweb.Lists.Add(“MyCirculation“,"Description", $spweb.Url, "a568770a-50ba-4052-ab48-37d8029b3f47", $listTemplate, 2)

You can get the feature ID from this location “14/TEMPLATE/FEATURES/CirculationList”
here I got this error message:

Exception calling "Add" with "6" argument(s): "The file or folder name contains characters that are not permitted.  Please use a different name

So I thought the error must be in the Url but what Url does the Method require?
Finally I tried with this:


$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::Circulation
$spweb.Lists.Add(“MyCirculation“,"Description", “MyCirculation“, "a568770a-50ba-4052-ab48-37d8029b3f47", $listTemplate, 2)

I don’t know why, but it worked. I just used the same thing for Title and Url.
I only tried this out with Circulations, but as whereabouts throw the same error I think the solution must be the same.

As I said this cost me about 6 hours trying and searching for a solution. I hope it will be useful to someone else.

Enjoy and Share :) 

Keine Kommentare:

Kommentar veröffentlichen