I am experimenting with PowerShell and script signing. I have created a sample script.
Write-Host "hello, world"
I further created a self-signed certificate and installed it (as administrator) to a trusted certificate store "TrustedPeople". Then I activated the execution policy
Set-ExecutionPolicy -scope process AllSigned
After that the script could not be executed anymore. That's expected. So I've signed the script:
Set-AuthenticodeSignature -FilePath .\hello.ps1 $cert
The variable $cert
still contains the self-signed certificate. After that I got this message when I started the script:
Do you want to run software from this untrusted publisher?
File C:\temp\hello.ps1 is published by CN=Ich and is not trusted on your system. Only run scripts from trusted publishers.
[V] Never run [D] Do not run [R] Run once [A] Always run [?] Help (default is "D"):
Due to a bad localization of the PowerShell I chose the wrong answer [E]:
[E] Noch nie ausgeführt [N] Nicht ausführen [M] Einmal ausführen [A] Immer ausführen
In that state I can't execute the script anymore. Removing and re-installing of the certificate didn't help. How can I restore the state before this mistake?
Edit: While I am experimenting I can delete the cert and create a new one. But what happens if I have distributed the scripts and the cert and this mistake happens on another PC? Purging the cert isn't an option in that case. Therefore I actually restore the cert.