如何通过PowerShell为Pfx证书设置FriendlyName并上传至Azure WebApp
解决PFX证书设置FriendlyName后上传Azure WebApp的问题
你之前的操作仅修改了内存中的证书对象,并未将更新后的FriendlyName保存到本地PFX文件,因此上传时仍使用原证书,导致设置不生效。正确的做法是将修改FriendlyName后的证书重新导出为新的PFX文件,再用新文件完成上传。
步骤1:修改证书FriendlyName并导出新PFX
使用PowerShell完成证书修改与导出:
# 定义原证书路径和密码 $originalCertPath = "XYZ\XYZC.pfx" $originalPassword = ConvertTo-SecureString "你的原PFX密码" -AsPlainText -Force # 加载原证书 $cert = Get-PfxCertificate -FilePath $originalCertPath -Password $originalPassword # 设置目标FriendlyName $cert.FriendlyName = "XXXTest" # 定义新证书存储路径和导出密码(可与原密码一致) $newCertPath = "XYZ\Modified_XYZC.pfx" $exportPassword = ConvertTo-SecureString "你的导出密码" -AsPlainText -Force # 导出修改后的证书 Export-PfxCertificate -Cert $cert -FilePath $newCertPath -Password $exportPassword
步骤2:上传新证书到Azure WebApp
使用修改后的PFX文件执行上传命令:
New-AzWebAppSSLBinding -ResourceGroupName "resourceName" -WebAppName "webAppName" -CertificateFilePath $newCertPath -CertificatePassword "你的导出密码" -Name "webAppName"
注意事项
- 确保原PFX证书包含私钥,否则无法正常导出并用于SSL绑定
- 在Azure Cloud Shell中操作时,需先将原PFX文件上传至Shell可访问路径(可使用
Upload-File命令上传本地文件)
内容的提问来源于stack exchange,提问作者Chhaya
相关产品推荐
相关产品推荐

