Search code examples
iisbatch-fileiis-6home-directory

IIS6 bat file - Home Directory


How do I get the Root/Home Directory of a website in IIS6 using a batch file??

My Scenario:

I am creating a tool to summarise and report of sites in IIS. I am using batch files and running iisweb /query to get all the sites then looping over the results and using iisvdir /query "Website Name" to get the virtual directories.

However it has to be backwards compatible with IIS6 and I am having trouble getting the Home Directory of the site.


Solution

  • I don't think you can do this directly from a batch file, but you should be able to do it from a vbscript which you can call from a batch file.

    The trick is to use the IIS WMI provider which gives you access to the IIS metabase. For example, the script below should echo the name and path of every virtual directory on the local server.

    set provider = GetObject("winmgmts://localhost/root/MicrosoftIISv2") 
    set results = provider.ExecQuery("SELECT Name,Path from IISWebVirtualDirSetting")
    for each item in results
      WScript.Echo item.Name
      WScript.Echo item.Path
    next
    

    If you saved this script as iispaths.vbs (just as an example), you could then call it from a batch file with:

    cscript //nologo iispaths.vbs
    

    Unfortunately I don't have access to a machine with IIS6, so I am unable to test this at the moment, but if you have any problems getting it to work, feel free to let me know in the comments and I'll do my best to fix the issue.