I have obtained a code signing cert from our trusted CA. I am trying to sign a script in PowerShell ISE but getting "UnknownError." I have tried encoding the script as UTF-8, but I'm still getting the same error. I have verified the script is UTF-8 as well.
$cert=(dir cert:currentuser\my\ -CodeSigningCert)Set-AuthenticodeSignature C:\Scripts\Certtestnew.ps1 $cert
Even though I'm getting "UnknownError", it still appears to sign the script. Although, when I run the script, I receive "The contents of file C:\Scripts\Certtestnew.ps1 may have been tampered because the hash of the file does not match the hash stored in the digital signature."
UPDATE $cert info:
PSPath : Microsoft.PowerShell.Security\Certificate::currentuser\my\FDCD31216C3491C2809441344EE6EF5E01EB0550PSParentPath : Microsoft.PowerShell.Security\Certificate::currentuser\myPSChildName : FDCD31216C3491C2809441344EE6EF5E01EB0550PSDrive : CertPSProvider : Microsoft.PowerShell.Security\CertificatePSIsContainer : FalseEnhancedKeyUsageList : {}DnsNameList : {}SendAsTrustedIssuer : FalseArchived : FalseExtensions : {System.Security.Cryptography.Oid,System.Security.Cryptography.Oid, System.Security.Cryptography.Oid, System.Security.Cryptography.Oid...;}FriendlyName :IssuerName : System.Security.Cryptography.X509Certificates.X500DistinguishedName NotAfter : 10/29/2016 4:05:37 PMNotBefore : 10/29/2015 3:45:37 PMHasPrivateKey : TruePrivateKey :PublicKey : System.Security.Cryptography.X509Certificates.PublicKeyRawData : {48, 130, 5, 225...;}SerialNumber : 60A14A915A0FAFA12311B0998F5892C9SubjectName : System.Security.Cryptography.X509Certificates.X500DistinguishedNameSignatureAlgorithm : System.Security.Cryptography.OidThumbprint : FDCD31216C3491C2809441344EE6EF5E01EB0550Version : 3Handle : 578311520Issuer : CN=USER OU=Admin, OU=Admin and Service Accounts, DC=domoainSubject : CN=USER, OU=Admin, OU=Admin and Service Accounts, DC=domain