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.
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.”
Error was:
File C:\Scripts\Certtestnew.ps1 cannot be loaded. The contents of file C:\Scripts\Certtestnew2.ps1 may have been tampered because the hash of the file does not match the hash stored in the digital signature. The script will not
execute on the system. Please see “get-help about_signing” for more details…
+ CategoryInfo : SecurityError: ( , ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnauthorizedAccess
That’s odd… I would have expected to see Code Signing in your EnhancedKeyUsageList, but it’s empty. You’re also using a Crypto Next Generation certificate, which may be the cause of the problem. (I can tell this because your HasPrivateKey property is set to True, but PrivateKey is null. This happens right now in .NET when you’ve got a CNG cert, because there’s no built-in support for loading up private keys from CNG providers. Set-AuthenticodeSignature may not be compatible with this type of cert, but I’d have to try it to know for sure.)