Created
August 15, 2014 03:13
-
-
Save dealproc/b71da93fd910f1ec69c4 to your computer and use it in GitHub Desktop.
SSL Creation using NetSH
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## -------------------------------------------------------------------------------------- | |
## Input | |
## -------------------------------------------------------------------------------------- | |
$webSiteName = $OctopusParameters['WebSiteName'] | |
$bindingPort = $OctopusParameters["BindingPort"] | |
$bindingIpAddress = $OctopusParameters["BindingIpAddress"] | |
$bindingHost = $OctopusParameters["BindingHost"] | |
$bindingSslThumbprint = $OctopusParameters["BindingSslThumbprint"] | |
$bindingSslThumbprint = $bindingSslThumbprint.Replace("?", "") | |
$webRoot = $OctopusParameters["WebRoot"] | |
$applicationId = $OctopusParameters["ApplicationId"] | |
## -------------------------------------------------------------------------------------- | |
## Helpers | |
## -------------------------------------------------------------------------------------- | |
# Helper for validating input parameters | |
function Validate-Parameter($foo, [string[]]$validInput, $parameterName) { | |
Write-Host "${parameterName}: ${foo}" | |
if (! $foo) { | |
throw "$parameterName cannot be empty, please specify a value" | |
} | |
if ($validInput) { | |
if (! $validInput -contains $input) { | |
throw "'$input' is not a valid input for '$parameterName'" | |
} | |
} | |
} | |
## -------------------------------------------------------------------------------------- | |
## Validate Input | |
## -------------------------------------------------------------------------------------- | |
Write-Output "Validating paramters..." | |
Validate-Parameter $webSiteName -parameterName "Web Site Name" | |
Validate-Parameter $bindingPort -parameterName "Port" | |
Validate-Parameter $bindingSslThumbprint -parameterName "SSL Thumbprint" | |
Validate-Parameter $applicationId -parameterName "Application ID (From AssemblyInfo.cs in the web application's project.)" | |
## -------------------------------------------------------------------------------------- | |
## Configuration | |
## -------------------------------------------------------------------------------------- | |
$bindingInformation = "${bindingIpAddress}:${bindingPort}:${bindingHost}" | |
Write-Host ("Attempting to create SSL Binding") | |
Add-PSSnapin WebAdministration -ErrorAction SilentlyContinue | |
Import-Module WebAdministration -ErrorAction SilentlyContinue | |
$sslbind = "IIS:\SslBindings\!$bindingPort!" + "" + $bindingHost | |
Write-Host ("Binding " + $sslbind) | |
$exists = Get-Item $sslbind -ErrorAction SilentlyContinue | |
if (!$exists) { | |
Write-Host("Create as this doesn't exists.") | |
netsh --% http add sslcert hostnameport=${bindingHost}:${bindingPort} certhash=${bindingSslThumbprint} appid=${applicationId} certstorename=My | |
Write-Host ("SSL enabled") | |
} else { | |
Write-Host("Skip, this already exists.") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment