Managing Virtual Directory on IIS 7.5

Hello,

 

Hereby some scripts which allows you to create or delete virtual directories on a IIS 7.5 (More particuly FTP directories)

Creation of a Virtual Directory:

VBS:

' Connect to the WebAdministration namespace.
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")

' Define the parameters.
strVDirPath = "/TestDaniel"
strAppPath = "/"
strPhysicalPath = "D:\FileShares\TestDaniel"
strSiteName = "Default FTP"

' Create the new virtual directory.
oWebAdmin.Get("VirtualDirectory").Create _
    strVDirPath, strAppPath, strPhysicalPath, strSiteName

Powershell:

Import-Module WebAdministration
New-WebVirtualDirectory -Site "Default FTP" -Application "/" -Name TestDaniel -PhysicalPath "D:\FileShares\TestDaniel"

Deletion of Virtual Directory

VBS

' Connect to the WebAdministration namespace.
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")
Set VDs = oWebAdmin.InstancesOF("VirtualDirectory")
' Define the parameters.
strVDirPath = "/TestDaniel"

For each oVDir In VDs
 if oVDir.Path = strVDirPath then
  oVDir.Delete_
 end if
Next

Powershell

Import-Module WebAdministration
Remove-WebVirtualDirectory -Site "Default FTP" -Application "/" -Name "TestDaniel"

Additional information