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 –
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<span style="color: #007020">Add-PSSnapin</span> Microsoft.SharePoint.PowerShell <span style="color: #888888"># Variables</span> <span style="color: #996633">$libraryNames</span> = "Current Name" <span style="color: #996633">$newLibraryName</span> = "New Name" <span style="color: #996633">$siteCollection</span> = "https://domain" <span style="color: #996633">$exlusions</span> = "/personal/" <span style="color: #888888"># Get the Site Collection</span> <span style="color: #996633">$Site</span> = <span style="color: #007020">Get-SPSite</span> <span style="color: #996633">$siteCollection</span> <span style="color: #996633">$spWebApp</span> = <span style="color: #996633">$Site</span>.WebApplication <span style="font-weight: bold;color: #008800">foreach</span> (<span style="color: #996633">$allSites</span> <span style="font-weight: bold;color: #008800">in</span> <span style="color: #996633">$spWebApp</span>.Sites) { <span style="font-weight: bold;color: #008800">if</span> (!<span style="color: #996633">$exclusions</span> <span style="color: #333333">-contains</span> <span style="color: #996633">$allSites</span>.Url) { <span style="color: #888888">#exclude sites who's url matches an exlusion</span> <span style="font-weight: bold;color: #008800">foreach</span> (<span style="color: #996633">$Web</span> <span style="font-weight: bold;color: #008800">in</span> <span style="color: #996633">$allSites</span>.AllWebs) { <span style="color: #888888"># loop through all sites</span> <span style="font-weight: bold;color: #008800">foreach</span> (<span style="color: #996633">$list</span> <span style="font-weight: bold;color: #008800">in</span> <span style="color: #996633">$Web</span>.Lists) { <span style="color: #888888"># loop through every list in sites</span> <span style="font-weight: bold;color: #008800">if</span>(<span style="color: #996633">$libraryNames</span> <span style="color: #333333">-contains</span> <span style="color: #996633">$list</span>.Title) { <span style="color: #888888"># if library name matches a value in $librarynames array</span> <span style="color: #996633">$list</span>.ParentWeb.Url + "/" + <span style="color: #996633">$list</span>.RootFolder.Url <span style="color: #888888"># display link to list</span> <span style="color: #996633">$list</span>.Title = <span style="color: #996633">$newLibraryname</span> <span style="color: #888888"># Update the name of list</span> <span style="color: #996633">$list</span>.Update() <span style="color: #888888"># Update the list name in SharePoint</span> } } } } } |
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.
Best SharePoint Hosting Recommendation
ASPHostPortal.com provides its customers with Plesk Panel, one of the most popular and stable control panels for Windows hosting, as free. You could also see the latest .NET framework, a crazy amount of functionality as well as Large disk space, bandwidth, MSSQL databases and more. All those give people the convenience to build up a powerful site in Windows server. ASPHostPortal.com offers SharePoint hosting starts from $9.99. ASPHostPortal.com also guarantees 30 days money back and guarantee 99.9% uptime. If you need a reliable affordable SharePoint Hosting, ASPHostPortal should be your best choice.