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

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?

share|improve this question
    
What are the values of the $line properties and the $webTemplate? –  Matthias Feb 22 '12 at 16:42
    
$webTemplate = "Document Library" $line.Url = "processes"; $line.Description = ""; $line.Library = "Process Documenation"; –  nyn3x Feb 23 '12 at 14:54
    
What kind of object is $line? –  Anita Boerboom Mar 30 '12 at 9:39

3 Answers 3

up vote 3 down vote accepted

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/

share|improve this answer

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

share|improve this answer
    
I do have those at the beginning and the end of the script. Im using Start-SPAssignment -Global. –  nyn3x Feb 23 '12 at 14:52
    
I don't see that in your code. –  Supriyo SB Chatterjee Sep 12 '13 at 13:52
    
I stripped that out - but it's there anyway. –  nyn3x Nov 18 '13 at 13:41
    
then the vote on my post above needs to be corrected? –  Supriyo SB Chatterjee Nov 18 '13 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. –  Benny Skogberg Nov 18 '13 at 20:05

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
}
share|improve this answer
    
But isn't that the same code that I originally posted? Does your (display) title get set using this code? –  nyn3x Nov 19 '12 at 12:54

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.