Windows SharePoint Services (WSS) v3 includes a command line utility for administrators that allows you to perform numerous actions against your WSS v3 or Office SharePoint Server (MOSS) 2007 implementation. This utility, STSADM.EXE can be found in the [...]\12\BIN\
directory. The new version of STSADM.EXE includes the capability to add your own custom commands. This is a great vehicle for implementing your own custom administrative utilities instead of writing a separate command line or WinForm application to perform the same process.
Interested in building your own custom commands for STSADM.EXE? Check out a post by Tony Bierman on the SharePoint Solutions Team Blog that includes a great how to on this topic: Extending Stsadm.exe with Custom Commands using the ISPStsadmCommand Interface.
In the process of developing a Publishing site (aka: WCM site) in MOSS 2007, I’ve been building a few utilities that have helped me in accomplishing my goal, and I’ve decided to share these. This page contains my custom STSADM.EXE commands I’ve written for Web Content Management (WCM) developers. I’ll use this page to serve as my documentation, making available the latest build of my custom commands, etc.
If you wish to be notified when my STSADM.EXE WCM custom commands are updated, please subscribe to my blog as I’ll post updates there.
Version History
v0.8.7.1111 - released November 12, 2007 - fixed two issues with the
GenContentTypesXml
command (no longer including{}
in theID
and adds the missing to the section.- v0.8.7.1111 installer
- v0.8.7.1111 source
v0.8.7.1029 - released October 29, 2007 - tons of fixes and updates applied… see the link below for a detailed list of updates. Most importantly, PublishAllItems no longer has the OutOfMemory exception!
- v0.8.7.1029 installer - delivered via a WSS solution package finally!
- v0.8.7.1029 source
v0.5.0 - released November 15, 2006 - updated release adding better memory management and exception handling to the existing PublishAllItems command, added two new commands (GenSiteColumnsXml & GenContentTypesXml), and added unit testing to all three commands
- v0.5.0 binaries - installer & uninstaller batch files
- v0.5.0 source
v0.1.0 - released October 26, 2006 - initial release containing the PublishAllItems command
- v0.1.0 binaries only + installer
- no source released for v0.1.0
Installation Instructions
I’ve made the installation as painless as possible. Creating custom commands for STSADM.EXE involves two things:
- Create a strongly named assembly that implements the ISPStsadmCommand interface and deploying this assembly to the GAC.
- Create an XML file containing a manifest of all the custom commands and a pointer to the assembly that contains the implementation. This XML file is then copied to the
[...]\12\CONFIG\
directory.
With the v0.8.7.1029 release, installation is now a piece of cake. The entire solution is provided as a WSS solution package. Simply add the solution using STSADM as follows (assuming the WSP is in the root of C:\):
c:\[..]\stsadm.exe -o addsolution -filename c:\AndrewConnell.SharePoint.StsadmWcmCommands.wsp
With it added to the solution store, deploy it by going to Central Administration > Operations > Solution Management and deploy the solution.
Need to uninstall? Simply retract the solution and remove it using the functions on the Solution Management page.
List of Commands in AC’s STSADM.EXE WCM Custom Commands Suite
- PublishAllItems [details here]When developing a Publishing Site in MOSS 2007, you’re bound to have countless pages, page layouts, master pages, images, JavaScript files… and so many more types of files that are in some state of moderation flux. Of course, this traditionally isn’t a problem in a production environment… but you’re sure to hit it in development, UAT, or QA in building a new site… maybe even working on an existing site! The command PublishAllItems will traverse a site collection, check-in any checked-out items, approve any pending approval, and publish all items.
- GenSiteColumnsXml [details here]
The process of building an elements file for a WSS v3 Feature that creates new site columns upon activation is tedious and problematic due to the lack of a rich debugging environment… even when you can use the WSS v3 XML Schema (
WSS.XSD
). Instead, build the site columns using the browser interface and use this command to generate the elements XML file for you! Will it give you exactly what you want? Maybe (likely) not, but it sure is easier to have a file you can tweak and prune rather than building one from scratch… not to mention a faster development experience. - GenContentTypesXml [details here]
Similar to site columns, the process of building an elements file for a WSS v3 Feature that creates new content types upon activation is tedious and problematic due to the lack of a rich debugging environment… even when you can use the WSS v3 XML Schema (
WSS.XSD
). Instead, build the content types using the browser interface and use this command to generate the elements XML file for you! Will it give you exactly what you want? Maybe (likely) not, but it sure is easier to have a file you can tweak and prune rather than building one from scratch… not to mention a faster development experience.
AC’s STSADM.EXE WCM Custom Command Details
Command: PublishAllItems
Regardless of the moderation state of any item within the specified list, the PublishAllItems command will publish any item that’s checked-out, pending approval, or pending publishing.
The command has two required parameters and two optional parameters:
Argument | Description |
---|---|
-url | Required. The URL of any site within a site collection. |
-list | Required. Name of the list containing items to publish. |
-includeSubSites | Optional. If specified, the command will perform the same action on all lists of the same name in all subsites. |
-displayProgress | Optional. If specified, all check-in, approval, and publishing actions are logged to the command window. This makes it easier to see what is going on and the progress of the action. This switch was formerly called “verbose”. |
Regardless of the URL specified, PublishAllItems will execute at the root site within the site collection. The current version does not provide the capability to specify an individual site within a site collection, however it will be included in a future version.
To get help on the command, simply enter STSADM.EXE -help PublishAllItems
at a command window.
To run PublishAllItems, you can enter the following command at a command prompt (assuming you have created a new site using the Publishing Portal template provided out-of-the-box in the MOSS 2007 RTW release):
STSADM.EXE -o PublishAllItems -url http://wcm -list Pages
This command will publish all the items within the Pages list in the root web of the Publishing site found in the http://wcm1
site collection. Another example using the two optional parameters is shown below:
Special thanks to Angus Logan who passed along his console app that did a similar thing. I just added some error trapping and made it a custom command for STSADM.EXE, as well as much better memory management.
Command: GenSiteColumnsXml
This command will generate the CAML for a Feature elements manifest file for use in creating site columns in a site, or just those columns within a specific group.
The command has two required parameters and three optional parameters:
Argument | Description |
---|---|
-url | Required. The URL of any site within a site collection. |
-outputFile | Required. Fully qualified path and filename of the XML file to create containing the site columns. |
-groupFilter | Optional. If specified, the command will only include site columns belonging to this group within the specified site. |
-genNewGuids | Optional. If specified, the command replace the actual ID (GUID) of the site column with a new, random GUID. |
-stripNameSpaces | Optional. If specified, all instances of the hex-encoded HTML space (_x0020_) are removed from the name. |
To get help on the command, simply enter STSADM.EXE -help GenSiteColumnsXml
at a command window.
To run GenSiteColumnsXml, you can enter the following command at a command prompt (assuming you have created a new site using the Publishing Portal template provided out-of-the-box in the MOSS 2007 RTW release):
STSADM.EXE -o GenSiteColumnsXml -url http://wcm -outputFile "c:\siteColumns.xml"
This command will generate the CAML for a Feature element manifest file for use in creating the site columns defined in the http://wcm
site.
Command: GenContentTypesXml
This command will generate the CAML for a Feature’s element manifest file for use in creating the content types in a site collection, or just those content types within a specific group.
The command has two required parameters and three optional parameters:
Argument | Description |
---|---|
-url | Required. The URL of any site within a site collection. |
-outputFile | Required. Fully qualified path and filename of the XML file to create containing the content types. |
-groupFilter | Optional. If specified, the command will only include content types belonging to this group within the specified site. |
-stripNameSpaces | Optional. If specified, all instances of the hex-encoded HTML space (_x0020_ ) are removed from the name of any referenced site columns. |
-excludeParentFields | Optional. If specified, the site columns defined in the content type’s parent content type are not included in the list. |
To get help on the command, simply enter STSADM.EXE -help GenContentTypesXml
at a command window.
To run GenContentTypesXml, you can enter the following command at a command prompt (assuming you have created a new site using the Publishing Portal template provided out-of-the-box in the MOSS 2007 RTW release):
STSADM.EXE -o GenContentTypesXml -url http://wcm1 -outputFile "c:\contentTypes.xml"
This command will generate XML file for use as an elements manifest file in a WSS v3 Feature containing the content types (and their fields) in the http://wcm site.