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)

About these ads

23 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. 4 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. 6 Jonas October 18, 2011 at 2:25 pm

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

  4. 8 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. 9 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 :-)

  6. 11 Vineeth May 5, 2012 at 9:05 pm

    Reblogged this on VM.Blog. and commented:
    Good post on how to run PS scripts as “.exe”

  7. 12 Mark January 21, 2013 at 10:59 pm

    Is it possible to decompile the exe back to PS1 in order to view the source code?

  8. 14 Dirk February 11, 2013 at 2:18 pm

    Is it possible to add the Quest AD extension to this exe?

    • 15 Dmitry Sotnikov February 11, 2013 at 7:01 pm

      The cmdlets need to be installed on the target machine separately. If they are – you can obviously use them in the exe – just add the snapin in your code.

  9. 16 Geert April 4, 2013 at 1:58 pm

    If you compile your script to an exe this way, does the computer on which the file is executed need to have execution policy set to allow all?

    • 17 Dmitry Sotnikov April 4, 2013 at 6:48 pm

      I am actually no longer on the PowerGUI team – so I am not sure. You can give it a try – PowerGUI is now just a free download.

  10. 18 Anonymous April 4, 2013 at 8:39 pm

    Is there any way to have the .exe run from the x86 powergui. I am having a issue running the exe when trying to connect to a databse

    • 19 Dmitry Sotnikov April 6, 2013 at 5:10 am

      If you are on Windows x64 you should have both PowerGUI x64 and PowerGUI x86 installed. My understanding is that x86 PowerGUI will create x86 exe… However, I am not 100% sure. If this does not work – try asking in the forums at http://powergui.org


  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
  4. 4 Summary of 2nd Dutch PowerShell User Group – DuPSUG meeting with additional resources | blog.bjornhouben.com Trackback on June 8, 2013 at 12:51 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

RSS My company’s blog

  • Fun at HostingCon 2013
    The smell of the hosting industry’s finest is in the air, and of course we sent some of the Jelastic team to attend and proudly exhibit at HostingCon 2013 this week in Austin, Texas.  From what I have been reading, there are more than 50 scheduled sessions from Sales and Marketing, Technology, Issues and Trends and [...]The post Fun at HostingCon 2013 appear […]
  • Secure Access to Your Jetty Web Application
    Today’s post focuses on the web application security related features of Jetty app server. After reading this article you should be able to configure security realms to provide authentication and access control for your Jetty web application, as well as to grant access to your app for dedicated IP-addresses only. Before we start let’s examine what Jetty real […]
  • Software Stacks Market Share: May 2013
    We are back to update you with the latest trends in software stacks popularity for May 2013. This time we decided to collect the numbers in a different way to get more accurate statistics. As you remember previously we counted the number of the environments, where each software stack was used. We’ve changed the reporting [...]The post Software Stacks Market […]
  • Setting Up a Cronjob in Jelastic Cloud
    Cronjob allows you to configure regularly scheduled tasks so that the jobs can be run automatically at a pre-set point of time. It repeats itself and does not need any regular manual instructions. Cron automates your system and can be used for quite different purposes. This wonderful tool is a standard part of all sysadmins toolkit. Also cronjob has a [...]T […]
  • How to Deploy Joget Cluster into the Cloud
    Joget Workflow is an open source platform that allows you to build enterprise web applications easily, due to its rich set of tools. It is also a rapid application development platform that provides complete agile development capabilities, including consisting of processes, forms, lists, CRUD and UI; not just back-end EAI/orchestration/integration or the tas […]
  • Liferay Cluster in the Cloud
    Liferay Portal is one of the most popular Java CMSs in the world due to its impressive ease-of-use. Since we published the tutorial on Liferay deployment to the cloud we have seen an extremely positive reaction from its community. Also we have received multiple requests from Liferay fans asking about clustering, replication and fail-over capabilities in the […]
  • Mark Zbikowski Veteran Microsoft Architect Joins Jelastic
    Jelastic already has an impressive team of advisers including Serguei Beloussov, the founder of Parallels. We also have technical geniuses who endorse and use Jelastic including the father of Java James Gosling, David Blevins who founded the TomEE project, and Michael “Monty” Widenius, the author of the original version of the open-source MySQL database and […]

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 former employer - Quest Software, or my current employer - Jelastic or anyone else for that matter. All trademarks acknowledged.

© 2007-2013 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 67 other followers

%d bloggers like this: