5

I need to remove a big amount of virtual directories, some of them don't have associated physical directories.
Ideas?

user626528
  • 13,999
  • 30
  • 78
  • 146

2 Answers2

5

As you need to remove a large amount, I'm guessing you'll want to use some form of script.

IIS 6.0, using IISvdir.vbs( article @ MSDN):

At the command prompt, use the cd command to change to the directory where the Iisvdir.vbs script is installed. The default location for this file is systemroot/system32/iisvdir.vbs.

At the command prompt, type:

cscript iisvdir.vbs /delete "Sample Web Site" VirtualDirectoryName.

Substitute your Web site name and virtual directory name as appropriate. If there are spaces in the Web site name, use quotation marks around the Web site name, as shown in the preceding example.

IIS 7 using AppCmd.exe (article @ TechNet):

To remove a virtual directory, use the following syntax:

appcmd delete vdir /vdir.name: string

The variable vdir.namestring is the virtual path of the virtual directory.

For example, to remove a virtual directory named photos from the root application of a site named contoso, type the following at the command prompt, and then press ENTER:

appcmd delete vdir /vdir.name: contoso / photos

To remove a virtual directory named photos from an application named marketing in a site named contoso, type the following at the command prompt, and then press ENTER:

appcmd delete vdir /vdir.name: contoso / marketing / photos

HTH

ianbailey
  • 620
  • 5
  • 14
  • Couldn't get those commands to work, what did work was adding a trailing slash. 'appcmd delete vdir "Default Web Site/My_Virtual_Dir/"' would work, if you removed the trailing slash it didn't work. – Wotuu Feb 05 '14 at 14:21
1

You could also write an msbuild script to do this and use the msbuild extension pack which is available here. I have used this successfully to do exactly what you are saying for 100s of vdirs in iis 6 AND in iis 7.5.

Its pretty simple and took me longer to write the .proj file than it did to figure out how to do it.

have fun :)

the resultant msbuild target would look like as follows

  <Target Name="IIS7VirtualDirectories:Delete">
    <MSBuild.ExtensionPack.Web.Iis7Application
      TaskAction="Delete"
      Website="%(Application.WebsiteName)"
      Applications="@(Application)"
      MachineName="$(MachineName)"
      ContinueOnError="false"/>

     <MSBuild.ExtensionPack.Web.Iis7Website 
      TaskAction="DeleteVirtualDirectory" 
      Name="%(VirtualDirectory.WebsiteName)" 
      VirtualDirectories="@(VirtualDirectory)"
      ContinueOnError="false"
      MachineName="$(MachineName)"/>    
    </Target>

Where Application and VirtualDirectory are defined in an external proj file :)

krystan honour
  • 6,523
  • 3
  • 36
  • 63