-
Notifications
You must be signed in to change notification settings - Fork 1
/
DeployHookIIS.ps1
46 lines (38 loc) · 1.22 KB
/
DeployHookIIS.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
param(
[switch]$quiet
);
function Get-EnvironmentCertificateName {
if($env:CERTIFICATE_NAME -eq $null) {
Write-Host "Environment variable CERTIFICATE_NAME must be defined" -ForegroundColor Red
exit 1
}
return $env:CERTIFICATE_NAME;
}
function Get-EnvironmentCertificateThumbprint {
if($env:CERTIFICATE_THUMBPRINT -eq $null) {
Write-Host "Environment variable CERTIFICATE_THUMBPRINT must be defined" -ForegroundColor Red
exit 1
}
return $env:CERTIFICATE_THUMBPRINT;
}
$name = Get-EnvironmentCertificateName
$thumbprint = Get-EnvironmentCertificateThumbprint
try
{
Import-Module WebAdministration
foreach($binding in Get-WebBinding) {
$bindingCert = (Get-ChildItem -Path "Cert:LocalMachine\MY" | Where-Object { $_.Thumbprint -eq $binding.certificateHash })
if($bindingCert.FriendlyName -eq $name) {
if(!$quiet) {
Write-Host "Assigning $($thumbprint) to $($binding.bindingInformation)"
}
$binding.RebindSslCertificate($thumbprint, "my")
}
}
}
catch
{
Write-Host "Error assigning IIS certificate:" -ForegroundColor Red
Write-Host "$($_.Exception)" -ForegroundColor Red
exit 1
}