WMI: VBscript to enumerate IIS virtual directories

Posted February 25th, 2010 in iis by dirk adamsky

Today’s script is about Internet Information Server (IIS).
It enumerates all virtual directories on an IIS server.
The script is tested for server 2003 with IIS 6.0.
Due to the fact that most IIS servers are in a De-Militarized Zone (DMZ) the easiest way is to run the script on the server.

Follow the next steps to make and run the script (admin rights needed):

  • open your favorite text editor (mine is notepad++)
  • copy and paste the script into the editor (delete the line numbers)
  • save the script (for example c:tempvdirs.vbs)
  • copy the script to the webserver
  • start an rdp session to the webserver
  • at the webserver open a command prompt
  • go to “c:temp”
  • give “cscript vdirs.vbs” (without quotes) and enter

The script:

' Name : vdirs.vbs
' Description : script to enumerate IIS virtual directories
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 25-02-2010
' Level : beginner

strComputer = "."
Set objWMIService = GetObject("winmgmts:{authenticationLevel=pktPrivacy}\" & strComputer & "rootmicrosoftiisv2")
Set colVdirs = objWMIService.ExecQuery("Select * from IIsWebVirtualDirSetting")
For Each objVdir in colVdirs
    Wscript.Echo "Name: " & objVdir.Name & " ; HttpRedirect " & objVdir.HttpRedirect
Next
Set colVdirs = Nothing
Set objWMIService = Nothing

As said earlier: when you have questions/problems please give a reply.

You can also rate the script with the “star” rating below

Best regards,

Dirk Adamsky – Deludi BV

[adrotate group="2"]