Setting binding information with a dynamic IP addressRSS

1 reply

Last post Nov 03, 2009 03:10 AM by Leo Tang - MSFT

  • Setting binding information with a dynamic IP address

    Oct 30, 2009 10:37 AM|cmdcom|LINK

    Hey now,

    I'm new to this PowerShell/WebAdministration thing.  My script allows a user to enter an IP address for a new website.  This IP is used as part of the -bindings argument when the New-Item cmdlet is called.  -bindings expects a hash table as the argument type.  Thing is, I cannot figure out how to use a variable in the constructor of the hash table.  After Googling this issue extensively, I attempted a number of syntactical variations, none of which worked (for clarity, I've omitted the other parameters used by the cmdlet):

    -bindings @{label="protocol";Expression="http";label="bindingInformation";Expression={($ip) + ":80"}}


    -bindings @{"protocol" = "http";"bindingInformation" = {($ip) + ":80"}}


    -bindings @{"protocol" = "http";"bindingInformation" = ($ip) + ":80"} 

     All result in a runtime error of some sort.  In desperation,  I ended up with:

    $bindings = @{"protocol" = "http"}
    $bindings.Add("bindingInformation", "")
    $bindings["bindingInformation"] = $ip + ":80"


    -bindings $bindings

    This ran sucessfully, but the binding information for the new site was empty.  What am I doing wrong here?



    bindings hash table

  • Re: Setting binding information with a dynamic IP address

    Nov 03, 2009 03:10 AM|Leo Tang - MSFT|LINK


    Please do not use double quotation marks on the properties' name(for example: "protocol", "bindingInformation"), then test again.

    Below is an article about  some PowerShell cmdlets, hope helps :
    PowerShell Snap-in: Making Simple Configuration Changes to Web-Sites and Application Pools

    Please mark the replies as answers if they help or unmark if not.
    Feedback to us