IIS 6.0, Getting Information Using WMI - Playing with Virtual directories and Web applications (Page 4 of 5 )
Let us consider that I would like to retrieve all Virtual directories existing in my local IIS web server. You can simply use the following WMI script and get it executed through WSH at the command prompt:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftIISv2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM IIsWebVirtualDir",,48)
For Each objItem in colItems
Wscript.Echo objItem.AppRootEcho & " --> " & objItem.Name
Next
Within the above example, I am working with a class “IIsWebVirtualDir” available in the “\\root\MicrosoftIISv2” namespace. “IIsWebVirtualDir” mainly contains all directories, which are termed Virtual Directories. You can get plenty of other information using the same class.
If we wanted to know which web applications are currently running, along with their responsible application pools (as explained in second section), we can use the following script:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftIISv2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM IIsWebVirtualDirSetting",,48)
For Each objItem in colItems
Wscript.Echo "Name: " & objItem.Name & " -> Pool: " & objItem.AppPoolId
Next
Within the above example, I am working with a class “IIsWebVirtualDirSetting” available in the “\\root\MicrosoftIISv2” namespace. “IIsWebVirtualDirSetting” gets all the web settings or IIS settings for each and every Virtual Directory available in “IIsWebVirtualDir”. The next example is also based on the same class.
If you wanted to check and see all the virtual directories allowed with directory access, you have the following script:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftIISv2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM IIsWebVirtualDirSetting",,48)
For Each objItem in colItems
Wscript.Echo "Name: " & objItem.Name
& " -> browsing Enabled: " & objItem.EnableDirBrowsing
Next
Next: How about SMTP, POP3, FTP services in IIS? >>
More IIS Articles
More By Jagadish Chaterjee