RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


SharePoint Applied—Stsadm Is Your Friend : Page 2

I am a self-confessed command line junkie. Sure, I see value in GUIs—and they're great for getting accustomed to a tool—but after crawling, the command line lets you walk, run, and then fly!

Speeding Up Your Development
If only I had a penny for every second spent in front of the SharePoint spinner. It's true! I spend a lot of my life watching progress bars. For instance, the "my retirement" application has been stuck at two percent for a very long time now. I use Stsadm to help speed up my development in two main ways: Autopilot Mode and Time-Squishing Mode.

Autopilot Mode
While Stsadm won't speed up SharePoint, it will let you script common and repetitive tasks so you can execute a command and then go grab a cup of coffee while the command executes.

For example, the following sequence of commands deletes whatever I have done on a given URL, and recreates the application and site for me based on an out-of-the-box template:

   stsadm -o deletesite -url <oldUrl>
   stsadm -o createsite -url <newsiteurl> 
   -owneremail <owneremail> 
   -ownerlogin <ownerlogin> 
   -sitetemplate <templatename>
I know what you're thinking! What good is the above sequence of commands if the starting point always has to be one of the built-in site definitions?

Well, whenever I am ready to save a snapshot of my work that I'd like to revert to frequently, I export it as a site template. Then I use stsadm -o addtemplate to add that to a site on a different port. Finally, I use some backup/restore wizardry, all via Stsadm, to revert the site right back to the snapshot after running the preceding script. I leave it up to you to write such a script. You might ask, why not just use backup and restore? Well, sometimes I'd rather see my custom features deployed, just as I would deploy them in production, so I tend to script out Stsadm, just as if I were running it in production.

As I mentioned, this doesn't speed up SharePoint, but while this script runs, it gives me an opportunity to feverishly check my email and see if I won any Internet lotteries. Maybe that will bump my retirement progress bar a bit?

Time-Squishing Mode
Frequently I find myself writing code or developing functionality against some timer job within SharePoint that runs every few minutes—or worse, every few days or longer. I could keep twiddling with the system date and time to kick the job in, but my virtual machines like to sync their local time with the host time. If I changed both my host time and the virtual machine time, my emails would confuse my co-workers, because I'd end up sending an email without fixing my system time.

Luckily, I found a mechanism to squish time. Well, not quite, but I did find a way to squish such timer jobs to a schedule that runs every few minutes. You can find a generic way of squishing time for any service/job posted on my blog.

However, if all you need to do is to change the schedule of information management policy to minutes, instead of running it daily, you could use the following Stsadm command:

   stsadm -o setpolicyschedule -schedule
   "every 1 minutes between 0 and 59"
Now the information management policy will run every minute, so you can test your settings without waiting until tomorrow or changing the date/time manually. Similarly, if you wish to change the frequency at which SharePoint sends alerts from every five minutes to one minute, you could use the following Stsadm command:

   stsadm -o setproperty -propertyname 
   job-immediate-alerts -url <url> -
   propertyvalue "every 1 minutes 
   between 0 and 59"
Feel free to explore what other properties exist and how you can use them.

Writing Custom Stsadm Commands
Last but not least, while Stsadm has been around for a while, SharePoint 2007 comes with a number of new Stsadm commands. While Stsadm won't do everything you need it to out of the box, you can extend it by writing custom operations. You can find further details here.

I hope you enjoyed meeting my best friend in SharePoint land, the Stsadm.exe command. This article didn't even scratch the surface of the Stsadm iceberg; you can use Stsadm for much more. For example, you could ease deployment pains by packing your code in features, and activating them via the command line. You could deploy your code as solutions. Or you could manage your shared service providers. I highly encourage you to check out Stsadm.exe—it will definitely make your life with SharePoint simpler.

Sahil Malik Sahil Malik is a Microsoft MVP, INETA speaker, a .NET author, consultant and trainer, and a well-rounded overweight geek. He has a passion for SharePoint 2007, data access, and application architecture. Sahil loves interacting with fellow geeks in real time. His talks are full of humor and practical nuggets. His talks tend to be highly charged, fast moving, and highly interactive. Be sure to check out his blog.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date