I had a request to rename roughly 100 libraries in our SharePoint deployment recently and thought it would be a good time to dig into a bit of PowerShell.
In this post I’ll demonstrate how to loop through site collections, subsites, lists and finally how to filter and change a name of a list and I’ll also attempt to show a few interesting properties we can change.
The Code
For those of you just looking for a quick bit of code to use, this will loop through all lists excluding anything in the ‘personal’ directories and will then rename the lists as specified in the $newLibraryname variable. Feel free to use this code however you want.
Be sure to change the Variables at the top as required –
Add-PSSnapin Microsoft.SharePoint.PowerShell # Variables $libraryNames = "Current Name" $newLibraryName = "New Name" $siteCollection = "https://domain" $exlusions = "/personal/" # Get the Site Collection $Site = Get-SPSite $siteCollection $spWebApp = $Site.WebApplication foreach ($allSites in $spWebApp.Sites) { if (!$exclusions -contains $allSites.Url) { #exclude sites who's url matches an exlusion foreach ($Web in $allSites.AllWebs) { # loop through all sites foreach ($list in $Web.Lists) { # loop through every list in sites if($libraryNames -contains $list.Title) { # if library name matches a value in $librarynames array $list.ParentWeb.Url + "/" + $list.RootFolder.Url # display link to list $list.Title = $newLibraryname # Update the name of list $list.Update() # Update the list name in SharePoint } } } } }
Useful List Variables
Here’s a very short list of useful variables attached to lists which can be used to update options –
- $list.ForceCheckout – Returns $True or $False depending on whether Force Check out is enabled.
- $list.EnableModeration – Returns $True or $False depending on whether ‘Require content approval for submitted items’ is enabled.
- $list.AllowDeletion – Returns $True if the list can be deleted otherwise set to false to protect a list.
- $list.EnableFolderCreation – Returns $True of $False depending on whether folders can be created.
- $list.EnableVersioning – Returns $True of $False depending on whether versioning is enabled. I plan to write another short article on configuring this properly.
Hope this helps!
Das ist ein wertinhalt! 🙂
LikeLike