r/PowerShell • u/adbertram • Apr 23 '21
How to Sign a PowerShell Script (And Run It)
Hey guys,
u/junecastillote just wrote a shiny new blog post you may enjoy.
"How to Sign a PowerShell Script (And Run It)"
Summary: Are you wondering what script signing is and how to distinguish a signed script from a non-signed one? Look no further! In this article, you'll learn how to sign PowerShell scripts using digital certificates.
8
Apr 23 '21
Thanks for this. I planned to play with signing scripts in powershell this weekend in the lab.
3
u/HappyDadOfFourJesus Apr 24 '21
Caveat: Just because a script is signed DOESN'T mean it's safe to run in your environment.
3
2
u/projects67 Apr 24 '21
Can anyone here tell me why a non-signed script runs no problem as a startup script (via GPO) even though the computer PS execution policy is “restricted. ?” I assume by design, just curious why.
4
u/RockSlice Apr 24 '21
Considering how simple it is to bypass, PS execution policy should be considered a fat-finger safety measure, anyway, and not a security measure. Sort of like yellow safety tape.
3
u/dasookwat Apr 24 '21
It is intended to be this way: execution policy is a measure to prevent stupid actions, it's not a security measure at all.
2
1
u/vellius Apr 24 '21
I would guess the script runs under a "system" credential profile... probably has restrictions bypassed.
1
u/projects67 Apr 24 '21
Perhaps. But I believe I have sign in scripts running under the users profile too- and those also run too.
1
u/vellius Apr 24 '21
Then i suspect your policies are being applied in the wrong scope.
1
u/projects67 Apr 24 '21
I’m a novice. What do you mean? I have a slew of startup (machine) and logon (user) scripts that run via GPO
1
u/vellius Apr 25 '21
When you apply a policy on a machine (ex: RemoteSigned).. you need to specify a scope or else... it's applied only to your current console or user.
Using Localmachine would make sure that the policy is applied to everything
1
1
u/odaat2004 Apr 24 '21
Thanks for this. Never occurred to me to just ask my employer for an Authenticode certificate til I read this. That they probably actually have one available for users if you just ask. Now, to find the right service now request for it.
10
u/charliesk9unit Apr 24 '21
Noob here. Is the signed script only valid on the computer the certificate was generated?