Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

My heart sinks every time I see foo.bat next to foo.ps1, where foo.bat is just `powershell -ExecutionPolicy Unrestricted -Command foo.ps1` so that it's double-click-friendly.


I'm definitely guilty of doing that the very few times I had to write a powershell script.

But what's the alternative? What's the proper way of signing a script, and how much work is it to do that?


Just put your powershell file in an executable, its been around for ages.

https://gallery.technet.microsoft.com/PS2EXE-Convert-PowerSh...

Read more on how to use it at https://redmondmag.com/articles/2017/01/27/convert-a-powersh...


Then you'll have 3 files - the script, the exe, and a little bat file that reruns ps2exe for updates. :)


Over 18KB for a "Hello World" script (even a native EXE would be smaller)...? A "stub" batch file to execute it is a few dozen bytes at most.

Then again, those using PS probably don't care about such things being small and efficient anyway.


I didn't downvote you, but consider that I answered the GP's question and solved a problem they are having, and you added some snark.

There is plenty of talk in this space about trading off machine resources for programmer effectiveness, so while your gripe is technically accurate that ship has sailed long long ago.


"Furthermore “script execution” have to be allowed (see cmdlet: set-execultionpolicy)."

...and we're back to square one. :-)



Well, in my experience the double-click-convenience of .bat files (due to their default cmd.exe association) is the reason people do this, not just the execution policy.

To sign a script you run:

    Set-AuthenticodeSignature foo.ps1 $someCert
and make sure that $someCert 's pubkey is available on every user's computer.

The alternative is of course to get every user to run `Set-ExecutionPolicy Unrestricted` to solve the "problem" permanently.


Yea, there are a few things PS does that makes it almost useless.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: