PowerShell Code Signing (2/2)

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.

dir cert:currentuser\my\

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s