views:

593

answers:

2

I'm having real issues trying to add multiple serverbindings to a single website using powershell!

Currently i have the following code:

    function UpdateMetaBaseProperties($dirEntry, $Properties)
    {
        foreach($Prop in $Properties)
        {
         $KeyValue = $Prop.Split('=');  
         $dirEntry.psbase.Invoke("Put", ($KeyValue[0], $KeyValue[1]));
         $dirEntry.psbase.Invoke("SetInfo");  
         Write-Host "Setting property: $KeyValue";
        }
    }

which is working for single valued properties but i can't seem to work out how to add as multiple.

I've tried

  1. Passing as array (throws exception)
  2. Passing as comma seperated string (puts all the string into 1 host entry)
  3. Passing as semi-colon seperated string (puts all the string into 1 host entry)
  4. Running the put twice (only saves the last host entry)

I've been searching an searching on google but nothing seems to work!

Please help!! :(

A: 

You'll have a way easier time of it if you install the IIS powershell provider from www.iis.net ( http://www.iis.net/1664/ItemPermalink.ashx )

[E] PS> add-pssnapin webadministration
[E] PS> new-webbinding -?

NAME
    New-WebBinding

SYNOPSIS
    Adds a new Web site binding to an existing Web site.


SYNTAX
    New-WebBinding [[-Name] <String>] [-Protocol <String>] [-Port <UInt32>] [-IPAddress <String>] [-HostHeader <String>
    ] [-Force] [-WarningAction <ActionPreference>] [-WarningVariable <String>] [<CommonParameters>]


DESCRIPTION
    Adds a new Web site binding to an existing Web site.


RELATED LINKS

REMARKS
    To see the examples, type: "get-help New-WebBinding -examples".
    For more information, type: "get-help New-WebBinding -detailed".
    For technical information, type: "get-help New-WebBinding -full".
x0n
As I'm using IIS6 this really won't too well!!!! Thanks anyway!
caveman_dick
+2  A: 

Here you go:

$site = [adsi]"IIS://localhost/w3svc/$siteid"
$site.ServerBindings.Insert($site.ServerBindings.Count, ":80:$hostheader")
$site.SetInfo()
Nico
Thanks worked like a dream! :)
caveman_dick