我有一个SSL证书在Azure keyvault 。我需要通过powershell将此证书安装到Azure应用程序服务。
关于这个问题,我们可以从Azure key vault中下载SSL证书作为pfx文件,然后使用pfx文件为Azure Web应用配置SSL。
详细步骤如下。
Connect-AzAccount
$cert=Get-AzKeyVaultSecret -VaultName "your key vault name" -Name ""
$password="Password0123!"
$certBytes = [System.Convert]::FromBase64String($cert.SecretValueText)
$certCollection = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2Collection
$certCollection.Import($certBytes,$null,[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
$protectedCertificateBytes = $certCollection.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12, $password)
$pfxPath = "E:\mycert.pfx"
[System.IO.File]::WriteAllBytes($pfxPath, $protectedCertificateBytes)
New-AzWebAppSSLBinding -WebAppName $webappname -ResourceGroupName $webappname -Name $fqdn `
-CertificateFilePath $pfxPath -CertificatePassword $pfxPassword -SslState SniEnabled