Tuesday, July 9, 2013

How to enumerate all virtual directories from WMI (IIS 7.0+)

Here is a simple way of enumerating all IIS 7.0 (or IIS 8.0) virtual directories. IIS 7.0+ exposes WMI namespace called WebAdministration . One of simple access to the WMI data is using Powershell. Sure, other approaches such as VBScript, C++, C# will work but if Powershell might be simplest one, I guess.

So the steps are:
1. Run Powershell.
2. In Powershell, run the following command.

     PS> gwmi -namespace root\WebAdministration -class VirtualDirectory

IIS 7.0+ uses root\WebAdministration namespace and to check virtual directory read data from VirtualDirectory class.

3. If you want to check Web Application, run this:

     PS> gwmi -namespace root\WebAdministration -class Application