I recently had to use the built-in deleteweb command to delete a web site and was irritated to find that the command wouldn’t let me delete the web because it had sub-webs. I simply couldn’t live with that as it’s extremely frustrating to have to delete all the child webs one at a time. So I created a better deleteweb command, called simply gl-deleteweb2. It behaves exactly like the built-in deleteweb command except that you can pass in a "recurse" switch to have it delete recursively (delete the web and all it’s children). What was really nice is that it took me literally 2 minutes to create this command (nice change from some of the more challenging ones I’ve had lately).
The code is extremely simple:
Use this command just like deleteweb but pass in "-recurse" if you want to delete a web with sub-webs (this keeps the action explicit so the user understands that it will delete all sub-webs). The syntax of the command can be seen below:
C:\>stsadm -help gl-deleteweb2 stsadm -o gl-deleteweb2 Deletes a web. Parameters: -url <url of web to delete> [-recurse (delete all sub-sites)]
Here’s an example of how to delete a web recursively:
stsadm –o gl-deleteweb2 -url "http://intranet/WebWithChildren" -recurse