PowerShell

PowerShell: Convert .ps1 Files to .exe Files

Have you ever dreamed of creating exe files out of your PowerShell scripts? If yes, read on. In this post I will show you how you can create exe files with a small and simple program called ps2exe.

PS2EXE

First of all you need a tool that converts PowerShell scripts to exe files. Download it here:

https://gallery.technet.microsoft.com/scriptcenter/PS2EXE-GUI-Convert-e7cb69d5

Anmerkung 2020-07-31 165208

Sample Script “Cortana speaks”

Now I have prepared an example. It will make Cortana speak. Yes, you heard right, this time not Azure, Office 365 etc… finally something funny.

Here is an extract of the script. As you can see, I created the graphical menus with Windows.Forms.

Anmerkung 2020-07-31 165500

Curious and interested? Download the full script here: cortana_for_exe.zip

Now our ps2exe program comes into play …

Converting ps1 files to exe files with ps2exe

The following one-liner creates an exe file from the ps1 file. Note that I also provide an icon for our newly created program.


ps2exe.ps1 C:\temp\cortana_for_exe.ps1 `
C:\temp\cortana.exe -noconsole -nooutput -iconfile "C:\temp\cortana.ico" -verbose

The result looks like this:

Anmerkung 2020-07-31 170129

Aaaand action …

Anmerkung 2020-07-31 170205

Fantastic! Have fun!

Credits

Credits go to Ingo Karstein and Markus Scholtes for developing ps2exe. THANK YOU!

See also

PowerShell: Show hidden properties from an Object

Microsoft 365: List all Mailbox Forwarding Rules (Server)

Categories: PowerShell

Tagged as: ,

6 replies »

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.