Skip to content

Instantly share code, notes, and snippets.

@2ajoyce
Last active May 10, 2020 03:55
Show Gist options
  • Save 2ajoyce/1414666fe24fb031ea6987c2b485716f to your computer and use it in GitHub Desktop.
Save 2ajoyce/1414666fe24fb031ea6987c2b485716f to your computer and use it in GitHub Desktop.
Steps to create a self signed cert for signing powershell scripts

Steps to create a self signed cert for signing powershell scripts

  1. Get the current date: $date_now = Get-Date
  2. Get the expiration date: $extended_date = $date_now.AddYears(3)
  3. Create the cert: $cert = New-SelfSignedCertificate -certstorelocation cert:\localmachine\root -dnsname website.local -notafter $extended_date -Type CodeSigningCert
  4. Create a password: $pwd = ConvertTo-SecureString -String 'PASSWORD' -Force -AsPlainText
  5. Get the path of the cert: $path = cert:\localMachine\root' + $cert.thumbprint`
  6. Export the cert so it can be imported as a Trusted Root Certificate: Export-PfxCertificate -cert $path -FilePath ~\powershellcert.pfx -Password $pwd
    1. You might be able to skip this step. Since it's created as root I'm not sure if exporting / importing is necessary
  7. Get the cert once it is imported: $cert = @(Get-ChildItem cert:\CurrentUser\root -codesigning)[0]
  8. Sign something with the cert: Set-AuthenticodeSignature file_path_to_unsigned_file $cert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment