Change List or Library URL and Name

Recently had a scenario where I needed to move a bunch of libraries from different sites, to another farm. Every library was titled the same, so when I went to import the libraries, I ran into a small issue. Using a combo of Export-SPweb and Import-SPweb, I moved a library over, then updated the library url and name to the source site name.

if ((Get-PSSnapin “Microsoft.SharePoint.PowerShell” -ErrorAction SilentlyContinue) -eq $null)
{
Add-PSSnapin “Microsoft.SharePoint.PowerShell”
}

$webURL = “http://sharepointed.com/sites/taco”

$before = “LibBefore”
$after = “LibAfter”

#Change the URL of the library
$web = Get-SPWeb $webURL
$web.lists[$before].RootFolder.MoveTo($after)
$Web.Dispose()

#Update the library name
$web = Get-SPWeb $webURL
$list = $web.Lists[$after]
$list.Title = $after
$list.Update()
$web.Dispose()

Couple notes.
You might be able to shorten the script to rename and update in a couple lines of code.
If you use the script to change the URL of a list, the list will moved to the root of the site. it will no longer live at site/lists.

*I have not tested this with libraries or list that workflows associated with them. It’s also safe to assume any links to documents would be broken.*

3 thoughts on “Change List or Library URL and Name

  1. Thank you for a script .It saves my time.
    But there is an error in my case (i work with list not lib):
    #Update the library name
    $web = Get-SPWeb $webURL
    –> $list = $web.Lists[$after]
    Must be
    $list = $web.Lists[$before]
    because there is no list instance with new name at this moment=)

  2. Please find the tested code. 🙂

    #to change the Url of the library in the sharepoint site.
    if ((Get-PSSnapin “Microsoft.SharePoint.PowerShell” -ErrorAction SilentlyContinue) -eq $null)
    {
    Add-PSSnapin “Microsoft.SharePoint.PowerShell”
    }

    $webURL = “url……”

    $before = “dsfsdfsd”
    $after = “sdfsdf”

    #Change the URL of the library
    $web = Get-SPWeb $webURL
    $web.lists[$before].RootFolder.MoveTo($after)
    $list = $web.Lists[$before]
    $list.Update()
    $Web.Update()

Leave a Reply

Your email address will not be published. Required fields are marked *