Batch file to Delete Old Virtual Directories.

On some servers we have many old Virtual Directories created for previous versions of our application.
IIS user interface allows to delete only one in a time.
Fortunately we can use IIS scripts as described in

How to manage Web sites and Web virtual directories by using command-line scripts in IIS 6.0

I’ve created batch file DeleteOldVDirs.cmd

rem http://support.microsoft.com/kb/816568
rem syntax: iisvdir /delete WebSite [/Virtual Path]Name [/s Computer [/u [Domain]User /p Password]]

REM list all directories and create batch of deletes
iisvdir /query “Default Web Site”

echo “Enter Ctrl-C  if you want to stop deleting”
Pause
iisvdir /delete “Default Web Site/VDirName1”

iisvdir /delete “Default Web Site/VDirName2”

 
If the name of WebSite or Virtual directory contain spaces(e.g  “Default Web Site”), don’t forget to use double quotes.
Note that the batch doesn’t delete physical directories from flie system.You need to delete them using Windows Explorer, but it does support multiple selection!