I had just finished creating the gl-createwebapp command and was about to go and delete the test web applications that I had created while testing the command and I discovered that there is no built in stsadm command for deleting a web application. I took a look at the code that is called when deleting via the browser and decided that it was simple enough that I could recreate it as a command - can't have a create without a delete :). The command I created is called gl-deletewebapp.
The only tricky spot I had was that there was a couple of pieces of code that required the use of internal classes - fortunately I'm getting pretty good at making calls to these internal classes so it didn't really slow me down much. The main hang up was that the Unprovision() method of the SPWebApplication object doesn't allow you to specify whether you want to delete the IIS web site or not - it just defaults to deleting it.
I wanted this command to function like the browser equivalent so I had to use the internal UnprovisionIisWebSites() method along with the RetractSolutions method of the SPSolutions class. And to make sure that I was mirroring the code executed when using the browser I had to also set a timer job using an internal only class (there's gotta be a way around this one). The code to do all this is below:The syntax of the command can be seen below:
C:\>stsadm -help gl-deletewebapp stsadm -o gl-deletewebapp Deletes a web application. Parameters: -urlHere's an example of how to delete a web application without deleting the IIS web site or the content database:
Here's another example which will delete the IIS web site and the content database:stsadm –o gl-deletewebapp -url "http://webappname"
stsadm -o gl-deletewebapp -url "http://webappname" -deleteiiswebsite -deletecontentdb