Extending STSADM with Custom Commands

The STSADM command-line tool has become a mainstay for SharePoint 2003 administrators. As a front-end for the SharePoint object model, it provides essential commands for managing SharePoint sites and users, backing up and restoring site collections and installing or removing web part packages and site templates. But with all the new capabilities now available in SharePoint v3, can STSADM provide all the functionality we need?

Well, herein lies the beauty of the new STSADM architecture – it’s extensible. Now you can add your own custom commands to STSADM.

In a nutshell, here are the steps:

  1. Implement the ISPStsadmCommand interface in a strongly-named assembly that you place in the GAC, and
  2. Create an XML file in the 12CONFIG folder that describes your commands

The ISPStsadmCommand interface consists of 2 methods and looks like this:

The GetHelpMessage method is called to retrieve the text displayed by STSADM when the user requests help using the “-help” parameter. The Run method is called when the user executes the command.

Let’s implement a simple command that enumerates task items declared in task lists in a SharePoint site. The command will require one parameter to specify the url of the site to examine. To make it interesting, lets add an optional parameter that lets us filter the list on tasks assigned to a particular user. We’ll start by creating a class library project in Visual Studio.

For simplicity, we’ll include the custom configuration file in the solution and copy it to the 12CONFIG folder on each successful build. We’ll also install the assembly into the GAC each time the solution builds. Note that the custom configuration file follows a special naming convention of the form “stsadmcommands.<name>.xml”. The STSADM executable searches for files in the 12CONFIG folder that have names matching this pattern.

We’ll start with a default implementation and then test it to ensure that everything is working as expected.

After building the solution, we can now run our custom command. Note that our custom help text is available from the -help option of the STSADM command. However, when we attempt to run the command, we just get the placeholder text as output.

Now let’s implement the core functionality. We’ll need a method to display the details of each task in a given web. We’ll pass an additional parameter we can use to filter the list for a given user.

We’ll create another method to determine if a given task can be shown for a given user, based on the task assignment.

Now we can finish the Run command to enumerate the tasks for a given url.

Let’s create a portal site with a task list for testing our solution.

We can now run our custom command from the command line.

And we can supply the optional -user parameter to display only tasks assigned to a specific user.

Extending STSADM with custom commands is essential to making SharePoint administration more accessible. When deployed in conjunction with a given set of features, a custom command assembly can greatly simply the task of managing and configuring your custom solution.

<

p class=”zoundry_bw_tags”>

Technorati : , , , STSADM,
Del.icio.us : , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.