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