Retrieving All Virtual Directories for an IIS6 Website Using WMI

I want to list all the virtual directories belonging to a website with a specific name using WMI and PowerShell.

I know that I can list all the virtual directories on the server using the code below, but how can I filter out only those that belong to a particular site?

Get-WmiObject IIsWebVirtualDir -namespace "ROOT\MicrosoftIISv2" 
+2
source share
1 answer

Well, taking the simplest approach here and filtering based on the properties returned from your example, I would rather use the site id part in the Name property:

 Get-WmiObject IIsWebVirtualDir -namespace "ROOT\MicrosoftIISv2" | ` Where-Object { $_.name -like "W3SVC/1/*" } 

The above example shows only the virtual directories on the default website that was configured when IIS was first installed. It always has identifier 1.

Note: the backtick `after the line is a line continuation character (actually it is an escape character, but I avoid EOL), like _ in Visual Basic. I use this, so the ugly horizontal scrollbars do not appear in the code above.

-Oisin

+1
source

All Articles