Skip to content

Instantly share code, notes, and snippets.

@kfrancis
Created January 20, 2014 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kfrancis/8524444 to your computer and use it in GitHub Desktop.
Save kfrancis/8524444 to your computer and use it in GitHub Desktop.
Attempt at replacing the default bindings AFTER OctopusDeploy's feature has completed
if ([System.Version] (Get-ItemProperty -path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion").CurrentVersion -ge [System.Version] "6.1") { Import-Module WebAdministration } else { Add-PSSnapin WebAdministration }
Function ReplaceWebsiteBinding($sitename, $oldBinding, $newValue)
{
$wsbindings = (Get-ItemProperty -Path "IIS:\Sites\$sitename" -Name Bindings)
Write-Host "Found bindings:"
Write-Host ($wsbindings.Collection).length
for($i=0;$i -lt ($wsbindings.Collection).length;$i++)
{
Write-Host ($wsbindings.Collection[$i]).bindingInformation
if((($wsbindings.Collection[$i]).bindingInformation).Contains($oldBinding)){
($wsbindings.Collection[$i]).bindingInformation = $newValue;
}
}
Set-ItemProperty -Path "IIS:\Sites\$sitename" -Name Bindings -Value $wsbindings
}
Write-Host "Starting PostDeploy"
$siteName = ("MyApp-" + $OctopusParameters["Octopus.Environment.Name"])
Write-Host $siteName
ReplaceWebsiteBinding($siteName, "*:80:", "*:82:")
Write-Host "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment