Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PowerShell添加到IIS的绑定,而不覆盖现有的_Powershell_Iis_Octopus Deploy - Fatal编程技术网

使用PowerShell添加到IIS的绑定,而不覆盖现有的

使用PowerShell添加到IIS的绑定,而不覆盖现有的,powershell,iis,octopus-deploy,Powershell,Iis,Octopus Deploy,我们使用OctopusDeploy创建网站,并使用社区步骤网站上的创建网站模板。我稍微修改了它,以确保如果网站存在,它会添加默认绑定,但会删除所有现有绑定。有没有一种方法可以简单地向IIS添加一个绑定,如果该绑定已经存在(或忽略),则该绑定将被覆盖,而不会删除所有现有绑定 我们目前拥有的脚本如下: $bindingInformation = "${bindingIpAddress}:${bindingPort}:${bindingHost}" $sitePath = ("IIS:\Sites\

我们使用OctopusDeploy创建网站,并使用社区步骤网站上的创建网站模板。我稍微修改了它,以确保如果网站存在,它会添加默认绑定,但会删除所有现有绑定。有没有一种方法可以简单地向IIS添加一个绑定,如果该绑定已经存在(或忽略),则该绑定将被覆盖,而不会删除所有现有绑定

我们目前拥有的脚本如下:

$bindingInformation = "${bindingIpAddress}:${bindingPort}:${bindingHost}"

$sitePath = ("IIS:\Sites\" + $webSiteName)

$site = Get-Item $sitePath -ErrorAction SilentlyContinue
if (!$site) { 
    Write-Output "Creating web site $webSiteName" 
    $id = (dir iis:\sites | foreach {$_.id} | sort -Descending | select -first 1) + 1
    new-item $sitePath -bindings ($wsBindings[0]) -id $id -physicalPath $webRoot -confirm:$false
} else {
    write-host "Web site $webSiteName already exists"
    Set-ItemProperty -Path $sitePath -Name Bindings -Value ($wsBindings[0])
}
这句话似乎是:

        Set-ItemProperty -Path $sitePath -Name Bindings -Value ($wsBindings[0])
正在覆盖所有现有绑定,但我似乎找不到解决方法。

您可以使用cmdlet:

新网络绑定`
-Name$webSiteName`
-协议“http”`
-端口$bindingPort`
-IPAddress$bindingIpAddress`
-HostHeader$bindingHost

并使用cmdlet检查绑定是否已经存在。

您可以使用
新的WebBinding
,正如jisaak所说,这主要用于http

如果需要添加其他类型的绑定,则必须使用
newitemproperty
,而不是
setitemproperty

New-ItemProperty -path "IIS:\Sites\YourSiteName" `
    -name bindings -value @{protocol="net.pipe";bindingInformation="SiteName"}