Compile PowerShell scripts to exe

Script compilation to executable files is one of the features we have added in PowerGUI Pro 3.0.

You would likely want to use compile a script when you want to share it in the enterprise environment and you are not sure whether the other person is comfortable running scripts or you simply don’t want risking someone modifying the code.

To compile a PowerShell script:

  1. Open the script in PowerGUI Pro Script Editor,
  2. On the Tools menu, click Compile Script,
  3. Then specify the name and path for the exe file you want to create:

PowerShell Compiled scripts

The additional options you get are:

  • Show or hide the PowerShell Console window when executing the script,
  • Automatically close or keep the console window (if you do want to show it),
  • Protect the script source code by obfuscating it using a password you specify,
  • Add other PowerShell scripts  to the exe (if you have script which your main script is using).

[UPDATE] If your script access parameters – so will the exe file it generates. So for an executable generated from a script like:

param ($MyParam1, $MyParam2) "MyParam1: $MyParam1""MyParam2: $MyParam2"

You may use a command line like:
c:\Generated.exe -Arguments -MyParam2 "Value2" -MyParam1 "Value1"

 

To try this feature, you can install a trial version of PowerGUI Pro from here.

(Screenshot taken from the original PowerGUI 3.0 announcement which lists a lot of other great features we shipped in that release)

Advertisement

12 Responses to “Compile PowerShell scripts to exe”


  1. 1 Klaus Graefensteiner August 22, 2011 at 2:13 pm

    I like this feature.
    An extremely cool enhancement would be allow for other payloads that get compiled into the executable. I was thinking about assemblies and native executables.
    I have a PowerShell script that uses cURL.exe that I need to distribute as one executable.

    Klaus

    • 2 Dmitry Sotnikov August 22, 2011 at 7:33 pm

      Klaus, try adding cURL.exe as a “PowerShell script” Dependency – I have not tried this myself but it should probably work…

  2. 3 chrisjwarwick August 22, 2011 at 4:26 pm

    Excellent facility. I’ve had complications before trying to talk someone through starting PowerShell, setting execution policy etc etc – so this could simplify things in those cases.

    Of course, you can do this natively (and WPK, the pre-”ShowUI” code from James Brundage, let you produce exe’s from scripts quite easily) – but this is seamless.

    I assume you need PowerShell installed wherever the .exe is going to run – so I gues it could be a problem in some cases targetting legacy (e.g. XP) machines…

  3. 5 Jonas October 18, 2011 at 2:25 pm

    Is it possible to compile exe files with the basic version of Powergui?

  4. 7 Anonymous October 20, 2011 at 3:16 pm

    Is it possible (there’re any way(s)) to revert the code inside the exe back to Ps script?

  5. 8 Anonymous October 27, 2011 at 5:49 am

    a very nice feature.

    however you need to have all the cmdlets on the featured machine to i guess. it do not compile the cmdlets needed into the exe file (atleast not on my tests)
    so it is not only powershell.exe that is needed but also the cmdlets you want to use on the machine running the compiled file ?

    or am i doing something wrong here :-)


  1. 1 List Building Script | How Do I Build A List? Trackback on September 25, 2011 at 7:08 pm
  2. 2 List Building Script | How Do I Build A List? Trackback on September 26, 2011 at 8:30 am
  3. 3 PowerGUI 3.1 Released! « Dmitry’s PowerBlog: PowerShell and beyond Trackback on October 14, 2011 at 1:49 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s




My Recent Tweets

Archives

Legal

The posts on this blog are provided “as is” with no warranties and confer no rights. The opinions expressed on this site are mine and mine alone, and do not necessarily represent those of my employer Quest Software or anyone else for that matter. All trademarks acknowledged.

© 2007 Dmitry Sotnikov

Pages

 

August 2011
M T W T F S S
« Jul   Sep »
1234567
891011121314
15161718192021
22232425262728
293031  

Follow

Get every new post delivered to your Inbox.

Join 47 other followers