$filestosign = (dir -recurse-include *.ps1)
Set-AuthenticodeSignature $filestosign $signingcert
我可以注册一个文件夹中的所有我的PS1文件。但是有没有一种快速的方法来解决这个问题?
$filestosign = (dir -recurse-include *.ps1)
Set-AuthenticodeSignature $filestosign $signingcert
我可以注册一个文件夹中的所有我的PS1文件。但是有没有一种快速的方法来解决这个问题?
我玩了一下,来到这个解决方案: 签名附加在文件的末尾。我搜索字符串“SIG#开始签名块”知道Linenumbers我不需要任何更多的,显示了休息和写回:
function remove-signature ($signedFile = "D:\ps10\test.ps1")
{
$filecontent = Get-Content $signedFile
$filecontent[0..(((Get-Content $signedFile | select-string "SIG # Begin signature block").LineNumber)-2)] | Set-Content $signedFile
}
认为这应该工作。我的第一个想法是找到一种方法来选择两个字符串之间的区域:“SIG#Begin”和“SIG#End”。只是为了学习的目的,我会感兴趣的如何我可以做到这一点。
我怀疑这不是你所希望的答案,但我很肯定没有一个“Remove-AuthenicodeSignauture”cmdlet可以帮忙。
签名,正如我相信你知道的那样,涉及在脚本中添加注释部分。删除此评论部分应删除签名。但是,这是你需要编写自己的东西。
首先,您不需要两次调用'Get-Content $ signedFile';你可以在数组索引语句中使用'$ filecontent'。至于“找到一种方法来选择两个字符串之间的区域”,就像这样:'$ isOutsideSig = $ true; $ filecontent |其中{$ wasOutsideSig = $ isOutsideSig; if($ _。StartsWith('#SIG#')){$ isOutsideSig = -not $ isOutsideSig}; $ isOutsideSig - 和$ wasOutsideSig} | Set-Content $ signedFile' – 2011-02-13 16:02:55
这打破了我没有数字签名的一些脚本。谨慎使用。 – Robin 2015-02-13 12:38:42