Search code examples
powershellvbscriptvisual-studio-codesignwsh

Digitally Signing scripts in [VSCODE]


In our environment the two main scripting languages that we use are VBScript/WScript and PowerShell. Our PowerShell is set up so that all scripts have to be digitally signed. Inside the PowerShell ISE we added a menu item that saves the current working script and digitally signs it. We currently use a different editor for VBS/Wscript. Is there a way in VSCode to allow us to run a function within the environment to digitally sign the current PowerShell scripts?


Solution

  • Found my answer:

    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
    }