I'm using a PowerShell script to update page titles and PublishingPageLayout's in a particular web that has 391 pages. However, I'm finding that the longer the script runs, the slower each pages is updated, so I'm wondering how I can speed things up.
Here's my script (cut down for readability)
function ProcessSubWebs($currentWeb)
{
if([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($currentWeb))
{
$publishingWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($currentWeb)
$publishingPages = $publishingWeb.GetPublishingPages()
foreach ($publishingPage in $publishingPages)
{
if($publishingPage.ListItem.File.CheckOutStatus -eq "None")
{
UpdatePage -page $publishingPage
}
}
foreach($sub in $currentWeb.Webs)
{
if($sub.Webs.Count -gt 0)
{
ProcessSubWebs($sub)
}
}
Write-Host -ForegroundColor red "FINISHED"
}
else
{
Write-Host -Foregroundcolor Red "^ not a publishing site"
}
}
function UpdatePage($page)
{
$page.CheckOut();
Write-Host -Foregroundcolor green $page.Url;
$NewPageTitle = $page.Title.Replace("Questionmark - ","");
$page.Title = $NewPageTitle;
$NewPageLayout = "/_catalogs/masterpage/QM_KB_NoCommentsRatings.aspx, QM KB Article No Comments or Ratings";
$page.ListItem.Properties["PublishingPageLayout"] = $NewPageLayout;
$page.ListItem.Update();
$page.CheckIn("nothing");
$page.ListItem.File.Approve("Updated PageLayout and Title");
}
ProcessSubWebs(Get-SPWeb -identity http://my.server.com/products/help/v3/kbase)
I'm wondering if there is a way to 'close' or 'dispose' the page object? I'd tried just using .Close() and .Dispose() but they return errors. Is there another technique I can use to close each page after it's Approved, to make the script run faster?
I'm about to run the script on over 500 pages in multiple webs/sites.. but even if I find out afterwards, I think this would be useful info to know.
