Extending Stsadm Command


While going through the WSS v3 Object Model, I came across an important interface ISPStsAdmCommand. Initially, I wasn’t able to find any documentation as product is about to RTM and doc is not complete. After some  research and thankfully to an excellent post by Tony Bierman at http://sharepointsolutions.blogspot.com/2006/09/extending-stsadmexe-with-custom.html, got lot of information about this Interface.

I am not going to dig much into the API as it has been well covererd by Tony’s blog. At high level, this allows you to extend the operations provided by StsAdm command and use it to do common repetitive tasks like taking backups, giving rights etc.

ISPStsadmCommand has two interfaces

1. string GetHelpMessage ( string command )

which shows the help for how to use the operation.

Usage stsadm -help [operation]

2. int Run ( string command, StringDictionary keyValues, out string output )

which is called to run the logic of user implemented operation.

keyValues is the dictionary containing command line parameters and their value passed

output is of type out parameter and used to show the message to be shown on command line as a result of running the command.


To test and extend this interface, I created an operation to delete all Webs below a SPWeb recursively. There were some posts on forums that on deleting a child web (which is not a top level site), if it contains subwebs, deletion is not allowed. This becomes a pain as user has to delete all the subwebs individually and then only the child web can be deleted. I decided to provide this functionality as a stsadm command.

The implemented operation recursively get all the sites one by one and delete them, finally followed by the child site.

Command syntax

c:\> stsadm.exe -o DeleteWebRecursive -url http://sitename/webname

This will delete all the webs under web names “webname”

I am attaching the solution for this custom extended command without any warranties :).

Copy following content

– Copy the SiteDelete.dll present in bin directory to GAC.

– Copy the stsadmcommands.customsitedelete.xml file in root folder to “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG” folder


That’s all to start using the extended operation. Let me know in case of bugs or improvements.