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:
Select “Create new Self Extraction Directive file”:
“Extract files and run an installation command”
Type the title fo your package
Add a prompt user or not:
Display a license information
Now, add your PowerShell Script
Here, you need to type the following command:
PowerShell.exe -noprofile -Sta -executionpolicy bypass -File Get-Cmd.ps1
If you want to show or hide the window.
Display a finished message
Type the path where the package will be created:
If you need to restart the computer at the end of the script:
And finish
It’s done, your package is generated as “Get-Cmd.Exe”
Thanks for reading! You can follow me on Twitter @PrigentNico