« Previous Next »

Thread: Add webbinding only if it does not exist

Last post 09-29-2009 12:23 PM by rkr31. 1 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (2 items)

Sort Posts:

  • 09-29-2009, 11:44 AM

    • rkr31
    • Top 200 Contributor
    • Joined on 05-01-2007, 10:15 AM
    • Posts 30

    Add webbinding only if it does not exist

    Hi

    Apologies for all the questions.  Im having issues getting my head around powershell at the moment....

    How can i add a webbinding only if it does not already exist?  The following adds the binding, but if it already exists it still adds it but stops the site.  I would like to throw an exception if the binding already exists.

    $binding = (@{protocol="http";bindingInformation="*:80:binding1.site.com"})
    new-item "iis:\sites\$sitename" -type site -physicalPath c:\inetpub\$sitename\website -bindings $binding -id "$sitenumber"

  • 09-29-2009, 12:23 PM In reply to

    • rkr31
    • Top 200 Contributor
    • Joined on 05-01-2007, 10:15 AM
    • Posts 30

    Re: Add webbinding only if it does not exist

    Think i have solved it myself.   If anyone has a better idea feel free to post.

    if ($null -ne (get-webbinding | where-object {$_.bindinginformation -eq "*:80:site1.site.com"}))
        {
            throw "There is already a binding"
        }
        else
        {
            throw "This is not a current binding"
        }

Page 1 of 1 (2 items)
Microsoft Communities