Ever want an easier way to run your scripts? Or even better, an easier way to share them with others and maybe you don’t want them to mess with the code or even to see it? The best way I have found for all of those situations is to compile my script into an EXE. Doing so is not only easy but it can be done FREE of charge with the right IDE.
To accomplish this marvel of modern computing we are going to make sure we have a copy of PowerGUI installed on our machine, available for download here along with a bunch of great documentation. This may not be your PowerShell editor of choice and it doesn’t have to be, you can develop your script in whatever IDE you like and when its time to compile, open it in PowerGUI. PowerShell ISE is generally my editor of choice but I have been known to use PowerGUI thanks to a few features that it has which can be handy, aside from compiling, specifically the display of variables you are using and their values.
Once you have a copy of PowerGUI installed go ahead and open it and open the script you want to compile. In order to actually compile it all you have to do is click on the Tools Menu and “Compile Script” or even faster, CTRL+F9.
A dialog screen will open with a few options, where to create the EXE, framework etc. Generally I leave everything in here at default with the exception of “Show PowerShell Console window when the script is executed”. I don’t want the user to see the PowerShell screen, if I did then I wouldn’t have made the GUI, so I always turn this option off.
You will notice that once its finished compiling you will have the EXE and a config file. While I’m sure the config file holds some information that is useful at some point, I have yet to keep one and not delete it. Even with it gone your EXE will run smoothly, just keep in mind that its made in a scripting language so give it a few seconds to start up and run everything it needs too.