August 22, 2013

How to get all web sites Bindings with site names

Get-WebBinding can return the bindings for all your IIS web sites, but the name of the web site is not a property of the resulting object, you have to guess it from the ItemXpath property (not always usefull).

On the other hand Get-WebSite can return the Bindings and the web site name. But the Bindings property is a Microsoft.IIs.PowerShell.Framework.ConfigurationElement object witch must be expand to get to the Collection Property, witch must expand again to get to the BindingInformation. This is not an easy way to get to the BindingInformation and when you will get it you will have lost the site name associated.

My solution is to create a [pscustomobject] (Powershell v3 only) that will contain all the properties I need :

Foreach ($Site in get-website) { Foreach ($Bind in $Site.bindings.collection) {[pscustomobject]@{name=$Site.name;Protocol=$Bind.Protocol;Bindings=$Bind.BindingInformation}}}

No comments:

Post a Comment