Sunday, December 03, 2006
« Fitz is blogging but Maurice is leaving | Main | MOSS Personal Sites – Still Top Level  »

Now that I have added some content to our portal I want to approve and publish all pages in each publishing web.

To do this I've created a function that takes an MOSS PublishingPage object and a comment that will be added when we check-in, approve and publish.

 

# Function: Approve-PublishingPage
# Description: Approve a single page in a Publishing Web
# Parameters: publishingPage PublishingPage object
# comment Comment to accompany the check-in/approve/publish
#
function Approve-PublishingPage ([Microsoft.SharePoint.Publishing.PublishingPage]$publishingPage, [string]$comment)
{
" Publishing Page: " + $publishingPage.Name

$listitemfile = $publishingPage.ListItem.File

# Check item if checked out
if ($listitemfile.Level -eq [Microsoft.SharePoint.SPFileLevel]::Checkout)
{
   " Checking in page"
   $listitemfile.CheckIn($comment,[Microsoft.SharePoint.SPCheckInType]::MajorCheckin )
}


# If moderation is being used then handle the approval and publishing
if ($publishingPage.ListItem.ParentList.EnableModeration)
{
   $modInformation = $publishingPage.ListItem.ModerationInformation

   " Moderation Enabled"

   # Check for pending approval
   if($modInformation.Status -eq [Microsoft.SharePoint.SPModerationStatusType]::Pending)
   {
      " Approving"

      $listitemfile.Approve($comment)
   }

   # Publish
   if($modInformation.Status -eq [Microsoft.SharePoint.SPModerationStatusType]::Draft)
   {
   " Publishing"
   $listitemfile.Publish($comment)
   }
}
}

this function will be called from Approve-AllPagesInSPWeb

# Function: Approve-AllPagesInSPWeb
# Description: Loop through all the pages in a Publishing Web and checkin and approve them
# Parameters: web SPWeb object
# comment Comment to accompany the checkin/approve/publish
#
function Approve-AllPagesInSPWeb([Microsoft.SharePoint.SPWeb]$web, [string]$comment)
{

# Check this is a publishing web
if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web) -eq $true)
{

$pubweb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web);

"Checking $($pubweb.URL)" 

   $pubcollection=$pubweb.GetPublishingPages() 

   for($i=0; $i -lt $pubcollection.count; $i++)
   {
      Approve-PublishingPage $pubcollection[$i] $comment
   }

}

}

Now I'd like to use a foreach look around the GetPublishingPages collection but that's not possible due to lack of Generic support in PowerShell at the moment, so an index loop does the job.

To approve all pages in all webs we can pipe the SPWebs to a foreach loop and pass the SPWeb object to Approve-AllPagesInSPweb

$site = spsite "http://yourmossserver"
$site.allwebs | foreach-object {Approve-AllPagesInSPweb $_ "System Approval"}

Added as a function approveall it produces this output

 

In the next step I'll add a Contact WebPart to every page.

 

 

Monday, December 04, 2006 10:21:58 PM (GMT Standard Time, UTC+00:00)
It is exciting to see the enthusiasm for PowerShell management of SharePoint. I just wanted to make sure that users are aware of the need to make proper use of the Dispose() method on SharePoint objects to avoid performance problems. It would be great to see the inclusion of this method within the examples here -- especially in situations where SPSite objects are used extensively.

Anyone interested can read more about this at msdn here: http://msdn2.microsoft.com/en-us/library/ms778813.aspx.

Zach Rosenfield [MSFT]
Zach Rosenfield
Tuesday, December 05, 2006 10:29:35 AM (GMT Standard Time, UTC+00:00)
Zach,

Good point, that MSDN article is excellent. I'll add the Dispose methods to all the samples.
I did consider using it previously but I wanted to keep the code simple and figured that with PowerShell it wasn't that important as with a command line shell your session is normally short lived, at least mine are, maybe with PowerShell we'll see people having it open all the time.

Colin Byrne
Saturday, March 10, 2007 2:01:12 PM (GMT Standard Time, UTC+00:00)
TODAY I LOOK A GOOD ARCHIVES!!

Saturday, March 10, 2007 2:01:35 PM (GMT Standard Time, UTC+00:00)
Hello I like your page is interesting...
10/325 - Vicoprofen - Lortab- Tylenol #3- - Ativan
All Major Medications are available right here at:
Saturday, March 10, 2007 2:02:05 PM (GMT Standard Time, UTC+00:00)
In the same calification we can find drugs like!

Saturday, March 10, 2007 2:02:25 PM (GMT Standard Time, UTC+00:00)
Have a great day!
Comments are closed.