asp.net.netiisvirtual-directory

IIS API - Create virtual directories?


Just looking for the relevant documentation. An example is not necessary, but would be appreciated.

We have a situation where we are having to create 100s of virtual directories manually, and it seems like automating this would be a good way to make the process more efficient for now.

Perhaps next year we can rework the server environment to allow something more sane, such as URL rewriting (unfortunately this does not seem feasible in the current cycle of the web application).


Solution

  • Evidently you can also do this via PowerShell scripting:

    $objIIS = new-object System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root")
    $children = $objIIS.psbase.children
    $vDir = $children.add("NewFolder",$objIIS.psbase.SchemaClassName)
    $vDir.psbase.CommitChanges()
    $vDir.Path = "C:\Documents and Settings\blah\Desktop\new"
    $vDir.defaultdoc = "Default.htm"
    $vDir.psbase.CommitChanges()
    

    Here is the documentation: MSDN - Using IIS Programmatic Administration