views:

396

answers:

1

Given a server name and a physical path, I'd like to be able to hunt down the IISWebServer object and ApplicationPool. Website url is also an acceptable input.

Our technologies are IIS 6, WMI, and access via C# or Powershell 2. I'm certain this would be easier with IIS 7 its managed API. We don't have that yet.

Here's what I can do:

Get a list of IIS virtual directories from IISWebVirtualDirSetting and filter (offline) for the matching physical path.

$theVirtualDir = gwmi -Namespace "root/MicrosoftIISv2" `
    -ComputerName $servername -authentication PacketPrivacy `
    -class "IISWebVirtualDirSetting" `
    | where-object {$_.Path -like $deployLocation}

From the virtual directory object, I can get a name (like W3SVC/40565456/root). Given this name, I can get to other goodies, such as the IIS web server object.

gwmi -Namespace "root/MicrosoftIISv2" `
    -ComputerName $servername `
    -authentication PacketPrivacy `
    -Query "SELECT * FROM IisWebServer WHERE Name='W3SVC/40589473'" 

The questions, restated:

1) This is a query language. Can I join or subquery so that 1 WMI query statement gets web servers based on IISWebVirtualDir.Path? How?

2) In solving 1, you'll have to explain how to query on the Path property. Why is this an invalid query? "SELECT * FROM IISWebVirtualDirSetting WHERE Path='D:\sites\globaldominator'"

+2  A: 

In WQL, there isn't a JOIN operator. You will need to do that by saving both queries to a variable and do some post processing. However, for your second question, you need to escape the backslashes. It would be

"SELECT * FROM IISWebVirtualDirSetting WHERE Path='D:\\sites\\globaldominator'"
Andy Schneider