Sunday, February 14, 2010

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://localhost/sites/Sales
                         -ownerlogin LitwareServer\BrianC
                         -owneremail brianc@litwareinc.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\
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://localhost/sites/Sales
                         -ownerlogin LitwareServer\BrianC
                         -owneremail brianc@litwareinc.com
                         -sitetemplate STS#0

No comments:

Post a Comment