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"]

Dirk – I’m trying to run this on a w2k3 iis6 server, but I get this error: CScript Error: Execution of the Windows Script Host failed. (The parameter is incorrect).
I figured it was the site name so I changed it to what it is (after the & strComputer &), “w3svc2″), but that gives me this error: C:tempvdirs.vbs(9, 1) (null): 0×80041021
Any thoughts? Here is the only line I modified:
Set objWMIService = GetObject(“winmgmts:{authenticationLevel=pktPrivacy}\” & strComputer & “w3svc2″)
Thanks!
I figured it out – it was the :{authenticationLevel=pktPrivacy} . Removing that and running locally (as admin) gave me exactly what I was looking for.
Thanks Dirk! This saved me a lot of typing!
Hi Tom,
good that you already figured it out.
happy scripting
best regards,
dirk
Do you know how to list ALL virtual directories including relative path? Even with iisvdir I only get the virtual directories with absolute paths and not those relative to another.
Hi Ken,
I will check it for you next on monday.
Best regards,
Dirk Adamsky
Did you get the answer for Ken?
I’m in the same situation now, it’s getting only the virtual directorie: “Default Web Site”, and I need all of them.
Thanks.
Hi Akio and Ken,
Sorry for my late reply.
I found out this week that iis 6 has a standard vbscript to enumerate, create and delete virtual directories.
It is called iisvdir.vbs and can be found in c:windowssystem32 on your webserver.
The script can be run like this:
0. make a rdp connection to the web server
1. open a command prompt on the web server
2. give cd windowssystem32
3. give ‘cscript iisvdirs.vbs /query sitename’ (without the quotes, change sitename with your website name f.e. test.org)
4. give enter to run the script
I hope this gives you the right output.
Happy scripting,
Dirk Adamsky