views:

23

answers:

1

I want to list all virtual directories that belong to a web site with a certain name using WMI and PowerShell.

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

Get-WmiObject IIsWebVirtualDir -namespace "ROOT\MicrosoftIISv2"
A: 

Well, taking the simplest approach here and filtering based on the properties returned from your given example, I would probably opt to use the site identifier portion in the Name property:

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

The above example only shows virtual directories on the default website that is set up with IIS first install. This always has the identifier 1.

Note: the backtick ` after the bar is the line continuation character (actually it's the escape character, but I'm escaping the EOL,) like _ in Visual Basic. I'm using this so the ugly horizontal scrollbars don't show up in the code block above.

-Oisin

x0n
Was thinking if there is a way to use the server name to find the virtual dirs as I can't know the ID of the web site beforehand (not using the default site). :)
Crassy
Accepted as there doesn't seem to be any one-codeline answer
Crassy