Created
June 7, 2017 11:33
-
-
Save garfoot/6c37b5d83477c92eeab642776ce8366b to your computer and use it in GitHub Desktop.
Powershell script to renew all web apps' SSL certs that match the given domain
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
param( | |
[string] $Domain, | |
[string] $CertFile, | |
[string] $CertPassword | |
) | |
# This could all be done with a single PS line but it wasn't pretty! | |
$ProgressPreference = "SilentlyContinue" | |
Write-Host Downloading web app details -ForegroundColor Green | |
$apps = Get-AzureRMWebApp | |
# Get all of the web apps that have an SSL binding present for the given domain | |
$renewalApps = $apps | Where-Object { $_.HostNameSslStates | Where-Object { $_.Name.EndsWith(".$($Domain)") } } | |
foreach ($app in $renewalApps) { | |
Write-Host "Updating " -NoNewline | |
Write-Host $app.Name -ForegroundColor Green | |
# Update each binding that matches the domain with the new cert, maintaining the ssl state for it | |
$app.HostNameSslStates ` | |
| Where-Object { $_.Name.EndsWith(".$($domain)") } ` | |
| ForEach-Object { | |
Write-Host "`tUpdating cert " -NoNewline | |
Write-Host $($_.Name) - $($_.SslState) -ForegroundColor Yellow | |
$cert = New-AzureRmWebAppSSLBinding -ResourceGroupName $app.ResourceGroup -WebAppName $app.Name -SslState $_.SslState ` | |
-Name $_.Name -CertificateFilePath $certFile -CertificatePassword $certPassword | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment