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:
- Open the script in PowerGUI Pro Script Editor,
- On the Tools menu, click Compile Script,
- Then specify the name and path for the exe file you want to create:
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)

Subscribe by email

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
Klaus, try adding cURL.exe as a “PowerShell script” Dependency – I have not tried this myself but it should probably work…
Does this work? I am curious…
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…
Chris, yes, powershell.exe is indeed required – your assumptions are correct.
Is it possible to compile exe files with the basic version of Powergui?
Jonas, unfortunately, at the moment this is a Pro feature.
Is it possible (there’re any way(s)) to revert the code inside the exe back to Ps script?
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
You should be able to add the modules that your script needs using the Dependencies button. If this for some reason does not work for you – please post the repro steps to our forum at http://powergui.org
Reblogged this on VM.Blog. and commented:
Good post on how to run PS scripts as “.exe”
Is it possible to decompile the exe back to PS1 in order to view the source code?
This depends on whether you select the “Protect source code” checkbox.
Is it possible to add the Quest AD extension to this exe?
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.
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?
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.
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
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