Monday, April 21, 2008

The STSADM.EXE Command Line Utility

WSS ships with a handy command-line utility named STSADM.EXE. This utility allows you to run interactive commands from the Windows command line and to script batch files that accomplish administrative tasks such as creating, backing up, and restoring site collections. When you run this utility from the command line or from a batch file, you must pass the –o parameter followed by one of the supported operations. Here’s an example of a command line instruction to create a new site collection at a specific URL.

STSADM.EXE –o CreateSite –url http://mshehadeh/sites/blog

-ownerlogin mshehadeh\admin
-owneremail mail@mshehadeh.com
-sitetemplate STS#0

Note that this example has introduced line breaks between the parameters to make things more readable. However, you cannot actually use line breaks between the parameters when running the STSADM utility from the command line or from a batch file.
Keep in mind that the installation of WSS adds the STSADM.EXE utility to a WSS system directory deep within the Windows Program Files directory. If you want to be able to call this utility directly from the command line on your development workstation, you should add the following path to your configured System path.
c:\program files\common files\microsoft shared\web server extensions\12\bin\
This System path is known as 12HIVE

When you write a batch file, you should also assume that it might be run on a machine that does not have the proper System path configured. Therefore, you should write batch files that explicitly specify the location of the STSADM.EXE utility.

@SET STSADM="c:\program files\common files\microsoft shared\
web server extensions\12\bin\stsadm"
%STSADM% –o CreateSite –url
http://mshehadeh/sites/blog
-ownerlogin mshehadeh\admin
-owneremail
mail@mshehadeh.com
-sitetemplate STS#0

Once again, the line breaks in the preceding example are only for readability. You will want to remove them when writing an actual batch file.

No comments: