Publish all pages in a site collection with PowerShell

SharePoint front-end guru and general nice guy Ben from Web.0 contacted me recently to ask how he could publish multiple pages across a SP2010 site collection. It seems he’d been given a backup from an existing project with a fairly deep site structure and many many pages in various states of approval.

My first thought was to direct him to the Content and Structure tool. Unfortunately this wasn’t going to let him do what he needed to do as seen in the screenshot below:

Unable to publish all pages using the Content and Structure Tool

(Note, I think that by using Content and Structure it would be possible to do this on a library by library basis – although perhaps workflow or content approval may have to be disabled; would have to check more)

So where next? Well, fortunately Gary LaPointe has updated his awesome stsadm extensions for MOSS 2007 into PowerShell Cmdlets for SharePoint 2010. A quick google later and there it is: Publish-SPListItems. Give that a whirl Ben, says I. Two minutes later, error says Ben.

Hmmm, extremely unlikely that the PowerShell Cmdlets are broken so time for a quick look at the error message. It appears that his environment had a couple of custom list definitions – the features for which hadn’t come across in his backup.

Not a problem really, but it did raise an interesting point: we actually only wanted to run the command against pages anyway. So how to do that? Luckily it’s nice and straight forward with PowerShell to get hold of all the Pages Libraries in a site collection (using similar techniques to my previous post on Interrogating lists with PowerShell):

Get-SPSite "http://sitecollectionurl" | Get-SPWeb | ForEach {$_.Lists} | Where {$_.BaseTemplate -eq "850"} | ft ParentWebUrl, Title

Which on the out-of-the-box publishing site gives:

List Pages Libraries Using PowerShell

Now we have checked that we’re able to ‘get hold of’ the right lists we can simply pipe these into Gary’s cmdlet like so:

Get-SPSite "http://sitecollectionurl" | Get-SPWeb | ForEach {$_.Lists} | Where {$_.BaseTemplate -eq "850"} | Publish-SPListItems

And very quickly, we have all of our pages published across the site collection:

Successfully publishing all pages with PowerShell

share and enjoy
  • Print
  • Twitter
  • Digg
  • StumbleUpon
  • Yahoo! Buzz
  • Google Bookmarks
  • Facebook

1 comment to Publish all pages in a site collection with PowerShell

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>