Showing posts with label IIS. Show all posts
Showing posts with label IIS. Show all posts

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}}}

December 4, 2012

WebAdministration CmdLets in remote session error ‘The data is invalid. (Exception from HRESULT: 0x8007000D)’

If you tried to use the WebAdministration Powershell CmdLets in a remote session like this :

Invoke-Command -Session $rs -ScriptBlock {get-website 'Default Web Site'}

You probably received this error :

The data is invalid. (Exception from HRESULT: 0x8007000D)
    + CategoryInfo          : NotSpecified: (:) [Get-Website], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.IIs.PowerShell.Provider.GetWebsiteCommand
    + PSComputerName        : **********

From what I could found, Powershell encounter an error trying to serialize some members (properties) of the object it’s trying to send you back from the remote session.  There is two workaround.

#1 : Select only the properties you need :

Invoke-Command -Session $rs -ScriptBlock {get-website 'Default Web Site' | select name,id,state,PhysicalPath}

#2 : Exclude the properties that cause an error :

Invoke-Command -Session $rs -ScriptBlock {get-website 'Default Web Site' | select * -ExcludeProperty Bindings,limits,logfile,tracefailedrequestslogging,applicationdefaults,virtualDirectoryDefaults,ftpserver}

Of course you’ll have to try every property to find the ones that generate an error.

If you want to read a property that generate an error you should get that property in a separate call :

Invoke-Command -Session $rs -ScriptBlock {(get-website 'Default Web Site').limits }

If the property you want  is a collection also try getting it separately with the Collection property :

Invoke-Command -Session $rs -ScriptBlock {(get-website 'Default Web Site').bindings.collection | select * -ExcludeProperty certificateHash,certificateStoreName,isDsMapperEnabled}

June 28, 2012

How to enum IIS Website name and ID

 

$computername="Endor"
$WebService = [adsi]"IIS://$computername/W3SVC"
$WebService.psbase.children | where {$_.Keytype -eq "IISWebServer"} | select name,ServerComment