PoshTip #39 – How To Generate EXE from Your PowerShell Scripts?

This PoshTip is an update of the previous PoshTip #38.

Thanks to TobiasPSP (https://twitter.com/TobiasPSP), I learnt that IExpress tool is still available in Windows 10 and it can be used to package PowerShell script to EXE.

What is IExpress?

IExpress is a Microsoft utility included in several editions of Windows OS. IExpress is used to create a single self-extracting package from a set of files. Then this package can be used to install:

  • Applications,
  • executables,
  • drivers,

On top of that, you can create EXE from one or more PowerShell Scripts!

Let’s start creating a simple PowerShell Script that will display all the PowerShell cmdlets and then makes a pause:

Get-Command
Start-Sleep -Seconds 10

Save as “Get-Cmd.ps1”. Open “IExpress.exe” from the search dialog box:

iexpress1

Select “Create new Self Extraction Directive file”:

iexpress2

“Extract files and run an installation command”

iexpress3

Type the title fo your package

iexpress4

Add a prompt user or not:

iexpress5

Display a license information

iexpress6

Now, add your PowerShell Script

iexpress7

Here, you need to type the following command:

PowerShell.exe -noprofile -Sta -executionpolicy bypass -File Get-Cmd.ps1

iexpress8

If you want to show or hide the window.

iexpress9

Display a finished message

iexpress10

Type the path where the package will be created:

iexpress11

If you need to restart the computer at the end of the script:

iexpress12

And finish

iexpress14

It’s done, your package is generated as “Get-Cmd.Exe”

 

Thanks for reading! You can follow me on Twitter @PrigentNico

 

About Nicolas 282 Articles
I work as an IT Production Manager, based in Paris (France) with a primary focus on Microsoft technologies. I have 10 years experience in administering Windows Servers. . I am a Microsoft MVP for Cloud & Datacenter Management. I also received the PowerShell Hero 2016 award by PowerShell.0rg. And finally, I am "MCSE: Cloud Platform and Infrastructure", "MCSA: Windows Servers", "Administering & Deploying SCCM", and CheckPoint CCSA certified.