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