You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PowerShell/PowerShell ISE脚本中传入SSL证书密码

给PowerShell脚本添加PFX证书密码的方法

要在脚本中嵌入证书密码,需要将密码转换为PowerShell的SecureString类型,再传递给Get-PfxCertificate的-Password参数,修改后的脚本如下:

$certPath = "D:\Folder\SSLCertName.pfx" 
# 将明文密码转换为安全字符串
$certPassword = ConvertTo-SecureString "你的实际证书密码" -AsPlainText -Force
# 加载带密码的证书
$cert = Get-PfxCertificate -FilePath $certPath -Password $certPassword
Invoke-RestMethod -Method Get -Uri 'https://API_URL' -Certificate $cert

关键说明:

  • 把代码中的"你的实际证书密码"替换为证书的真实密码
  • -AsPlainText -Force是必须的参数组合,用于将明文密码转换为PowerShell要求的SecureString格式
  • 若担心硬编码密码不安全,可改用交互式输入方式,避免密码暴露在脚本中:
    $certPath = "D:\Folder\SSLCertName.pfx" 
    $certPassword = Read-Host "请输入证书密码" -AsSecureString
    $cert = Get-PfxCertificate -FilePath $certPath -Password $certPassword
    Invoke-RestMethod -Method Get -Uri 'https://API_URL' -Certificate $cert
    

内容的提问来源于stack exchange,提问作者Craig

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 03:59:51