$certificateName = Read-Host -Prompt 'Enter name of your certificate e.g. MyCert or [email protected]'$cert = New-SelfSignedCertificate -DnsName $certificateName -CertStoreLocation Cert:\CurrentUser\My\ -Type Codesigning -NotAfter (Get-Date).AddYears(3)
$certThumprint = Read-Host -Prompt 'Enter thumbprint of your certificate'$cert = Get-ChildItem -Path Cert:\CurrentUser\My\ | Where { $_.Thumbprint -eq $certThumprint }
This can be done manually using certmgr.msc or using the following commands:
- Export your certificate into a .cer file
Export-Certificate -Type CERT -Cert $cert -FilePath $env:userprofile\documents\myCert.cerImport-Certificate -FilePath $env:userprofile\documents\myCert.cer -CertStoreLocation Cert:\CurrentUser\TrustedPublisherImport-Certificate -FilePath $env:userprofile\documents\myCert.cer -CertStoreLocation Cert:\CurrentUser\Root -Confirm
$pathToPs1File=Read-Host -Prompt 'Enter path to your ps1 script'Set-AuthenticodeSignature -FilePath $pathToPs1File -Certificate $cert