Powershell 分配证书

Powershell assigning a Certificate

我在 certmgr 中有证书,我也可以使用以下方法提取它:

$a=Get-ChildItem –Path cert:\CurrentUser\my –codeSigningCert

现在如何分配相同的代码签名证书来对我的所有脚本进行数字签名? 有什么直接的方法可以实现吗?

您可以使用 Set-AuthenticodeSignature cmdlet:

$Cert = Get-PfxCertificate -FilePath "C:\Test\Mysign.pfx"
Set-AuthenticodeSignature -FilePath "ServerProps.ps1" -Certificate $Cert

Set-AuthenticodeSignature c:\foo.ps1 @(Get-ChildItem cert:\CurrentUser\My -codesign)[0]

如果您想了解更多信息,请参阅 the MS link or this link