Monday, February 11, 2013

Change Document Library folders title through Power Shell


In this post we will see how to change the title of the folders in document library.

Here is before running the script.



Here is the script. If you are not aware what is happening in this script, I would recommend reading get value from configuration file post.

[xml]$xmlfile = Get-Content ConfigFile.xml
 $site = ''
$web = ''
$listName = 'Shared Documents'
 foreach( $sitecoll in $xmlfile.Configuration.SiteCollection)
{
    $site = $sitecoll.name              
}
 $spSite= Get-SPSite $site
 $web = $spSite.OpenWeb()
 Write-Host -foregroundcolor Green 'Site URL' $site
 $list=$web.Lists.TryGetList($listName)
 foreach($folder in $list.Folders)
{
if($folder['Title'] -eq 'Folder1')
{
   $folder['Name'] = 'NewFolder1'
   $folder['Title'] = 'NewFolder1'
   } elseif($folder['Title'] -eq 'Folder2')
{
    $folder['Name'] = 'NewFolder2'
   $folder['Title'] = 'NewFolder2'
 }
 elseif($folder['Title'] -eq 'Folder3')
{
    $folder['Name'] = 'NewFolder3'
   $folder['Title'] = 'NewFolder3'
 }
 elseif($folder['Title'] -eq 'Folder4')
{
   $folder['Name'] = 'NewFolder4'
   $folder['Title'] = 'NewFolder4'
 }
 elseif($folder['Title'] -eq 'Folder5')
{
    $folder['Name'] = 'NewFolder5'
   $folder['Title'] = 'NewFolder5'
 }
 $folder.update()
 }

we are opening the site and then taking the reference of the library and then iterate through all folders of the library and then compare the title of the folder and then change folder properties.

Once you run the script, all folders names and title will be changed. 


I hope this helps.


No comments:




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com