Now that we’ve completed step 1 and created a certificate, we can proceed to sign some code.
Open a PowerShell session and take a look at your certificates.
You’ll get a list of your certificates. If you have a bunch and want to confirm that there is a code signing certificate run:
dir cert:currentuser\my\ | select enhancedusage
to see what they all are or
dir cert:currentuser\my\ -CodeSigningCert
to only see the code signing certs
Store the cert in a variable to make the signing command easier to type. If you have several code signing certs you will need to reference the one you want to use (with the thumbprint), otherwise we can tell it just to give us the code signing cert.
$cs = dir cert:currentuser\my -CodeSigningCert
$cs = dir cert:currentuser\my\thumbprint
Now you can use the Set-AuthenticodeSignature cmdlet to sign your file.
Set-AuthenticodeSignature -Certificate $cs -FilePath C:\pathtoyourfile.ps1