Signing a script
suggest changeSigning a script is done by using the Set-AuthenticodeSignature-cmdlet and a code-signing certificate.
#Get the first available personal code-signing certificate for the logged on user
$cert = @(Get-ChildItem -Path Cert:\CurrentUser\My -CodeSigningCert)[0]
#Sign script using certificate
Set-AuthenticodeSignature -Certificate $cert -FilePath c:\MyScript.ps1
You can also read a certificate from a .pfx-file using:
$cert = Get-PfxCertificate -FilePath "C:\MyCodeSigningCert.pfx"
The signature is valid until the certificate expires. If you use a timestamp server while signing, the signature stays valid after the certificate expires. Including the trust chain (with the root authority) helps other computers trust the certificate that signed the script.
Set-AuthenticodeSignature -Certificate $cert -FilePath c:\MyScript.ps1 -IncludeChain All -TimeStampServer "http://timestamp.verisign.com/scripts/timstamp.dll"
Use a timestamp server from a trusted certificate provider. The Verisign URL below is the historical endpoint (timstamp.dll is the real path). Confirm that it still answers before you rely on it.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents