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)
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)
$spweb.Lists.Add(“MyCirculation“,"Description", $spweb.Url, "a568770a-50ba-4052-ab48-37d8029b3f47", $listTemplate, 2)
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)
$spweb.Lists.Add(“MyCirculation“,"Description", “MyCirculation“, "a568770a-50ba-4052-ab48-37d8029b3f47", $listTemplate, 2)
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