I wasn't planning on creating this command but then I ran my gl-replacefieldvalues command and forgot to pass the "-publish" switch in so now I was stuck with all these list items that needed to be published and/or approved. When this happened I thought, no problem - Andrew Connell has a PublishAllItems command so I'll just download his stuff and use that rather than create my own. Unfortunately however, Andrew's command didn't take all scenarios into account and thus I was left with the task of creating a new command to do what Andrew's attempted.
For those that are using Andrew's command without issue I decided to name mine "gl-publishitems" so as to not step on his command thus allowing both to be installed. The main problem I had with Andrew's command was that it didn't take into account items that needed approval but which did not have an SPFile object associated with it. There were also issues where he was calling SPListItem.Update() after a checkin which would throw an error because the update call requires the file to be checked out.
Andrew's code also didn't take into account workflows that would need to be canceled as a result of approving an item. And finally his code didn't allow all the scoping options that I needed (Farm, Web Application, Site Collection, Web, or List). The large bulk of the code is just a series of methods with different loops in them to handle the various scoping capabilities (similar to what I did with gl-replacefieldvalues).
The core code itself is considering all the cases in which an item may need to be either checked in, published, and/or approved. I've also added the ability to dump all changes to a log file as well as to run the command in a "test" mode where it will show you what it would publish but not actually make any changes - I'd strongly recommend you use this first to verify all the changes that will be made. The core code is shown below:The syntax of the command I created can be seen below:
C:\>stsadm -help gl-publishitems stsadm -o gl-publishitems Publishes all items at a given scope. Use -test to verify what will be published before executing. Parameters: [-url <url to publish>] -scope <Farm | WebApplication | Site | Web | List> [-quiet] [-test] [-logfile <log file>]
Here's an example of how to publish all items in a given site collection:
stsadm -o gl-publishitems -url "http://intranet/hr" -scope site -logfile "c:\publish.log"