1

I want to create libraries in SharePoint 2010 using PowerShell. So far, so good.

I'm using this chunk of code to create the library (actually list, but that doesn't matter)

    $listTemplate = $currentWeb.ListTemplates | ? {$_.name -eq $webTemplate }
    $newListId = $currentWeb.Lists.Add($line.Url, $line.Description, $listTemplate)
    $newList = $currentWeb.Lists[$newListId]
    $newList.Title = $line.Library
    $newList.OnQuickLaunch = $addToQuickLaunch
    $newList.Update()

But for some strange reason the (display) title of my library doesn't get set to whatever is in $line.Library.

Any hints?

3
  • What are the values of the $line properties and the $webTemplate? Commented Feb 22, 2012 at 16:42
  • $webTemplate = "Document Library" $line.Url = "processes"; $line.Description = ""; $line.Library = "Process Documenation"; Commented Feb 23, 2012 at 14:54
  • What kind of object is $line? Commented Mar 30, 2012 at 9:39

3 Answers 3

3

Is your site in English or is your site in some other language, maybe German. If your site is NOT english, you CAN't update list's title once you've created it unless you manipulate thread's UI culture to match your site's language.

The following blog posts could be helpful in the scenario of not having an english site:

http://blog.andersdissing.com/2011/07/change-powershell-ui-culture.html

http://www.sharepointblues.com/2011/11/14/splist-title-property-spfield-displayname-property-not-updating/

0

Use a 'Start-SPAssignment/Stop-SPAssignment' pair around your code block. More on Start_SPAssignment here.

6
  • I do have those at the beginning and the end of the script. Im using Start-SPAssignment -Global. Commented Feb 23, 2012 at 14:52
  • I don't see that in your code. Commented Sep 12, 2013 at 13:52
  • I stripped that out - but it's there anyway. Commented Nov 18, 2013 at 13:41
  • then the vote on my post above needs to be corrected? Commented Nov 18, 2013 at 14:04
  • @nyn3x How can the one answering your question know what you have left out on your question? Please update your question to give those who take the time answering a chance to make reasonable judgment of what is and what is not present. Commented Nov 18, 2013 at 20:05
0

I'd suggest to check out the following site, as they are doing something similar. It looks like from what I'm saying it may be determinate on what your object is -- in this case -- they had it seperated out as a string. Have you tried to check what those output as you were debugging?

See below, from site,

function New-SPList {
<#
.Synopsis
    Use New-SPList to create a new SharePoint List or Library.
.Description
    This advanced PowerShell function uses the Add method of a SPWeb object to create new lists and libraries in a SharePoint Web
    specified in the -Web parameter.
.Example
    C:\PS>New-SPList -Web http://intranet -ListTitle "My Documents" -ListUrl "MyDocuments" -Description "This is my library" -Template "Document Library"
    This example creates a standard Document Library in the http://intranet site.
.Example
    C:\PS>New-SPList -Web http://intranet -ListTitle "My Announcements" -ListUrl "MyAnnouncements" -Description "These are company-wide announcements." -Template "Announcements"
    This example creates an Announcements list in the http://intranet site.
.Notes
    You must use the 'friendly' name for the type of list or library.  To retrieve the available Library Templates, use Get-SPListTemplates.
.Link
    http://www.iccblogs.com/blogs/rdennis
        http://twitter.com/SharePointRyan
.Inputs
    None
.Outputs
    None
#>    
    [CmdletBinding()]
    Param(
    [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
    [string]$Web,
    [Parameter(Mandatory=$true)]
    [string]$ListTitle,
    [Parameter(Mandatory=$true)]
    [string]$ListUrl,
    [Parameter(Mandatory=$false)]
    [string]$Description,
    [Parameter(Mandatory=$true)]
    [string]$Template
    )
Start-SPAssignment -Global
$SPWeb = Get-SPWeb -Identity $Web
$listTemplate = $SPWeb.ListTemplates[$Template]
$SPWeb.Lists.Add($ListUrl,$Description,$listTemplate)
$list = $SPWeb.Lists[$ListUrl]
$list.Title = $ListTitle
$list.Update()
$SPWeb.Dispose()
Stop-SPAssignment -Global
}
1
  • But isn't that the same code that I originally posted? Does your (display) title get set using this code? Commented Nov 19, 2012 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.