Share via


"Set-AuthenticodeSignature" returns Unknown Error while registering the script with a certificate

Recently I have been working on a PowerShell Project where I needed to sign the scripts with the code signing certificates (the ExecutionPolicy was set to "AllSigned").

I did this before many times without a single problem/error. But this time when I tried to sign the scripts with the certificates I got the “Unknown” error message returned on the PowerShell console.

It was totally bewildering experience…I didn’t know what to do. Then I realize the only difference this time is that I was using PowerShell ISE to write the scripts (whereas earlier I have been using Notepad to create the scripts).

Now the question comes what the problem using ISE then?

Answer is PowerShell ISE by default saves the scripts file (ps1) in “Unicode big endian” and that doesn’t work while signing the scripts.

Workaround is you can use the Notepad to change the encoding to UTF-8 and then sign the script. Everything will be fine now.

Other workaround is to save the file in ISE by changing the ISE’s current encoding: $psISE.CurrentFile.Save([Text.Encoding]::UTF8)

Hope this helps many!

Vijay

Comments

  • Anonymous
    April 23, 2011
    Very nice post :) The 48 hours to sign my first script ;) thanks to you.

  • Anonymous
    May 06, 2011
    You saved my life... about 6 hours wasted :( Thanks a LOT

  • Anonymous
    April 19, 2012
    You are a STAR!!! Thanks a lot!! Marco - StockTrader