Geeks With Blogs
Clara's Notes on Technology Notes to me and the world

Today I had to change the title of several pages in several publishing sites. You can find the powershell script below.

Notice that you have to access the pages as PublishingPage and not SPListItem,otherwise you will not be able to modify the Title field ("Title" is ReadOnly). Also, you have to go through the same procedure as in the UI: checkout, change property, checkin and publish (and maybe approve if the library requires it).

Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue 

#read list

$lines = Get-Content "C:\SharePoint2010\PowerShell\sites.txt" #| Sort-Object

foreach($l in $lines)
        $a = $l.split(";");
        $url = $a[0]
        $title = $a[1]               
        $spWeb = Get-SPWeb -Identity $url
        if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($spWeb))
            $spPubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($spWeb)
            $pages = $spPubWeb.PagesList
            foreach($item in $pages.Items)
                $pubPage = [Microsoft.SharePoint.Publishing.PublishingPage]::GetPublishingPage($item)
                if ($pubPage.Title -eq "wrong title")
                    $pubPage.Title = $title
                    $pageFile = $pubPage.ListItem.File;
        Write-Host -BackgroundColor DarkGreen -ForegroundColor White ("Done: " + $url);      
        Write-Host -BackgroundColor DarkRed -ForegroundColor White ("Failed:" + $url + ". Error details : " + $_)      

The input file contains the url of the site and the title of the page, separated by a semicolon. Like this:

http://<servername>/home/site1/site2;Correct Title for page



Technorati Tags: PowerShell, SharePoint

Posted on Thursday, November 25, 2010 5:17 AM SharePoint , Powershell | Back to top

Comments on this post: Powershell: Change Title of PublishingPage

# re: Powershell: Change Title of PublishingPage
Requesting Gravatar...
Am i able to change all the title tags all at once? or do i have to run this one at a time?
Left by Sammy on Nov 25, 2010 5:31 AM

# re: Powershell: Change Title of PublishingPage
Requesting Gravatar...
This script changes the title of pages in the Pages library from "wrong title" to the new title. For all the pages that have this title in this library and this site.
Left by claraoscura on Nov 25, 2010 6:14 AM

Your comment:
 (will show your gravatar)

Copyright © Clara Oscura | Powered by: