Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i remove signing from Powershell?

so with

$filestosign = (dir -recurse-include *.ps1)
Set-AuthenticodeSignature $filestosign $signingcert

i can sign all my ps1 files in a folder. But is there a quick way to undo this again?

like image 417
icnivad Avatar asked Mar 08 '26 23:03

icnivad


1 Answers

I played a bit around and came to this solution: The signature is appended at the end of a file. I search for the string "SIG # Begin signature block" to know the Linenumbers i don't need any more, display the rest and write this back:

function remove-signature ($signedFile = "D:\ps10\test.ps1")
{
$filecontent = Get-Content $signedFile
$filecontent[0..(((Get-Content $signedFile | select-string "SIG # Begin signature block").LineNumber)-2)] | Set-Content $signedFile
}

Think this should work. My first thought was to find a way to select the area between the two strings: "SIG # Begin" and "SIG # End" . Just for learning purpose i would be interrested how i could have done that.

like image 62
icnivad Avatar answered Mar 10 '26 16:03

icnivad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!