Powershell中为VBScript脚本签名


你可能知道Set-AuthenticodeSignature能够为Powershell脚本实现数字签名,但你知道它还能为其它脚本做签名吗?

这里小段代码将从PFX文件加载一个数字证书,然后扫描你家目录下的VBS文件,同时给脚本申请数字签名:

# 改成你的PFX文件路径点
$pfxpath = 'C:\Users\Tobias\Documents\PowerShell\testcert.pfx'

#改成访问这个PFX文件的密码
# 这个密码是你生成PFX文件时设置的。
$password = 'topsecret'

# 加载证书
Add-Type -AssemblyName System.Security
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$cert.Import($pfxpath, $password, 'Exportable')

#给全部的VBS脚本文件申请证书

#去掉-WHATIF参数将真正申请签名
Get-ChildItem -Path $home -Filter *.vbs -Recurse -ErrorAction SilentlyContinue |
  Set-AuthenticodeSignature -Certificate $cert -WhatIf

原文地址:Signing VBScript Files with PowerShell

本文链接: https://www.pstips.net/signing-vbscript-files-with-powershell.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

发表评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注