欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Powershell读取PFX证书并输入密码的脚本分享

程序员文章站 2022-03-31 09:21:32
支持所有ps版本 当你使用get-pfxcertificate读取pfx证书去签名你的脚本,但是它总是会已交互式方式提示用户去输入密码。 下面介绍怎么通过脚本去提交密码...

支持所有ps版本

当你使用get-pfxcertificate读取pfx证书去签名你的脚本,但是它总是会已交互式方式提示用户去输入密码。

下面介绍怎么通过脚本去提交密码:

复制代码 代码如下:

$pathtopfxfile = 'c:\temp\test.pfx'
$pfxpassword = 'test'
 
add-type -assemblyname system.security
$cert = new-object system.security.cryptography.x509certificates.x509certificate2
$cert.import($pathtopfxfile, $pfxpassword, 'exportable')
 
$cert