在 [VSCODE] 中对脚本进行数字签名

CFo*_*CFo 3 vbscript powershell sign wsh visual-studio-code

在我们的环境中,我们使用的两种主要脚本语言是 VBScript/WScript 和 PowerShell。我们的 PowerShell 设置为所有脚本都必须经过数字签名。在 PowerShell ISE 内部,我们添加了一个菜单项,用于保存当前工作脚本并对其进行数字签名。目前,我们对 VBS/Wscript 使用不同的编辑器。VSCode 中有没有办法允许我们在环境中运行一个函数来对当前的 PowerShell 脚本进行数字签名?

CFo*_*CFo 5

找到了我的答案:

Register-EditorCommand -Name SignCurrentScript -DisplayName 'Sign Current Script' -ScriptBlock {
    $cert = (Get-ChildItem Cert:\CurrentUser\My -CodeSigningCert)[0]
    $currentFile = $psEditor.GetEditorContext().CurrentFile.Path
    Set-AuthenticodeSignature -Certificate $cert -FilePath $currentFile
}
Run Code Online (Sandbox Code Playgroud)

  • 将其添加到您的 C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.VSCode_profile.ps1 按 Shift-Alt-S 它应该列在那里。 (2认同)