In WMI, can I use a join (or something similar) to acquire the IisWebServer object for a site, given

Posted by Precipitous on Stack Overflow See other posts from Stack Overflow or by Precipitous
Published on 2010-02-09T01:59:17Z Indexed on 2010/05/10 21:34 UTC
Read the original article Hit count: 305

Filed under:
|
|
|

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'"

© Stack Overflow or respective owner

Related posts about wmi

Related posts about wmi-query