How to Create .EXE Files With PowerShell

Problem Scenario 
You want to package a standalone .ps1 script as an .exe file.  How do you create an executable file that does what a PowerShell script does?

Install PowerShell Community Extensions.  Then download this .ps1 file and use it according to the conventions in the comments, near the top, of the script itself,

The usage instructions are in the code.  We found that the -NET40 flag was needed.  Here is an example that assumes four things: 1) you saved the file as "Make-PS1ExeWrapper.ps1" (but this is optional and just an example) 2) the script you want to convert is named "good.ps1" 3) the directory the PowerShell prompt is in is the directory with the two files just mentioned 4) you want the new .exe file to be called good.exe.

>  .\Make-PS1ExeWrapper.ps1 .\good.ps1 .\good.exe -NET40

The actions of good.ps1 will run whenever you double click the good.exe file.  You may transfer good.exe to any Windows machine and run it.

Leave a comment

Your email address will not be published. Required fields are marked *