Search code examples
c#iis-7wmi

WMI - IIS 7 - Retrieve all website bindings


Im trying to find some sample code that shows how use the WMI ( using C#) to query a remote IIS 7 for all website bindings. I cant make heads or tails of all the classes/ name spaces and querys that need to be made to accomplish this. If no sample code is available i would love some refrences to good documentation.

Thanks alot


Solution

  • You need to use the ServerManager.OpenRemote("serverName") function to connect to an external IIS instance. (See the msdn article here.)

    If you enumerate through serverManager.Sites collection you can then retrieve the site.Bindings property from each Site object to see the bindings that are active on that website.