r/PowerShell • u/TheBigBeardedGeek • May 21 '26
Question Does anyone have an easy guide for signing scripts?
I really need to sign my scripts, but unfortunately my brain tends to shut down when it comes to cert things aside from just "load file." Appreciate it!
40
Upvotes
28
u/Icolan May 21 '26
$File = [Path to Script to be signed]Set-AuthenticodeSignature -FilePath $File -Certificate $(Get-ChildItem -path Cert:\CurrentUser\My -CodeSigningCert | Select-Object -First 1) -TimeStampServer [URL of Preferred TimeStamp server]You can turn the above into a function for your profile so you can call it passing the file name as a parameter.
Get a code signing cert from your internal CA, if you have one, or from a reputable online CA, if you don't.
9
u/Procedure_Dunsel May 21 '26
Walk-through of the entire process https://patchmypc.com/kb/how-generate-code-signing-certificate/
The video here is pretty good too https://askgarth.com/blog/how-to-code-sign-powershell/
5
u/purplemonkeymad May 21 '26
Hate to tell you, but it may be worth learning about PKI for these kinds of things. Will also help you get your head around adding server certificates, encryption, etc.
11
u/an_harmonica May 21 '26 edited May 21 '26
Does anyone ever bother looking up Microsoft's documentation for literally ANYTHING before asking questions on Reddit?
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_signing?view=powershell-7.6
5
u/hardingd May 21 '26
If you have an internal PKI for Active Directory, you can create a code signing cert and sign the script. Otherwise, buy a signing cert from a reputable company (Digicert etc). Chat GPT is your friend here.
2
u/VladDBA May 21 '26
If you're using a code-signing cert from Certum, I wrote down in this blog post the process I use to code-sign PSBlitz.
2
u/TheBlueFireKing May 21 '26
There are enough guides how to creatr the cert. After that I just have a shortcut in VSCode where I can press F2 and Enter to sign any open script. Makes it pretty easy and not annoying to sign then.
2
u/Nuxi0477 May 21 '26
The most improtant thing is to remember to use a timestamp server. Otherwise your program/script/whatever will stop working when the cert expires. With a timestamp it will (always) remain valid as long as the cert that signed it was valid at the time of signing.
1
u/EskimoRuler May 21 '26
u/asjimene has a cool tool to right-click code-sign using a powershell script
https://github.com/asjimene/RightClickCodeSign
1
u/JustAnITGuyAtWork11 May 21 '26
I have a gui tool which I found years ago that I use. I'll share it tomorrow/later tonight
1
u/g3n3 May 23 '26
Id probably step back. You know execution policy doesn’t have teeth. If you aren’t using WDAC, then the sigs don’t matter too much. So why sign?