Skip to content

About

PowerShell script that turns any folder into a Windows Installer (.msi) package with zero dependencies. It uses the built-in Windows Installer API and makecab. Installs to Program Files, adds a Start Menu shortcut and an Apps & features icon, and supports upgrades and clean uninstall.

Topics

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

MSI Installer Creator

Turn any folder into a Windows Installer package (.msi) with a single PowerShell script.

.\MSIInstallerCreator.ps1 -SourceFolder .\build -ProductName ExampleName -Version 1.0.0 -Manufacturer "Contoso"

The resulting MSI installs the folder's contents into %ProgramFiles%\ExampleName\ and adds an ExampleName shortcut to the Start Menu.


Contents


Features

  • Zero dependencies: uses the built-in Windows Installer COM API (msi.dll) and makecab.exe.
  • Single-file output: files are compressed (LZX) into a cabinet embedded inside the .msi.
  • Whole folder trees: subfolders, empty folders, long file names, spaces and non-ASCII names (e.g. café.txt) are all supported.
  • Start Menu shortcut for all users, pointing at your executable, with the install folder as its working directory.
  • Per-machine install into C:\Program Files\<ProductName>\ (or Program Files (x86) for x86 packages).
  • Apps & features / Programs and Features entry with name, version, publisher, install location and icon. The icon is taken automatically from your executable, or from an .ico you supply.
  • Major upgrades: installing a newer version automatically replaces the old one.
  • Downgrade protection: installing an older version over a newer one is refused with a clear message.
  • Clean uninstall: files, folders, shortcut and registration are all removed.
  • Stable identifiers: the UpgradeCode and component GUIDs are derived deterministically, so repeated builds of the same product upgrade each other correctly without you having to track GUIDs.

Requirements

Requirement Notes
Windows 10 / 11 (or older Windows with PowerShell 5.1 installed) Developed and tested on Windows 10 22H2.
Windows PowerShell 5.1 Built into Windows 10/11. PowerShell 7 should also work, but 5.1 is what's tested.
makecab.exe Ships with Windows in C:\Windows\System32.

Building the MSI does not need administrator rights. Installing it does (it installs per-machine into Program Files), and Windows will show a UAC prompt.

Quick start

  1. Put the files your application needs into a folder, for example .\build:

    build\
    ├── ExampleName.exe
    ├── ExampleName.dll
    └── data\
        └── settings.json
    
  2. Run the script:

    .\MSIInstallerCreator.ps1 -SourceFolder .\build -ProductName ExampleName -Version 1.0.0 -Manufacturer "Contoso"

    If PowerShell refuses to run the script because of the execution policy, run it like this instead:

    powershell -ExecutionPolicy Bypass -File .\MSIInstallerCreator.ps1 -SourceFolder .\build -ProductName ExampleName -Version 1.0.0 -Manufacturer "Contoso"
  3. You get ExampleName-1.0.0.msi in the current folder:

    Compressing 3 file(s)...
    Writing C:\work\ExampleName-1.0.0.msi...
    
    Created C:\work\ExampleName-1.0.0.msi
      Product      : ExampleName 1.0.0 (x64)
      Files        : 3
      Shortcut     : Start Menu\ExampleName -> ExampleName.exe
      Icon         : ExampleName.exe
      UpgradeCode  : {D54EE7EF-7965-34A5-A115-D0B8967D6DF2}  (keep this the same for future versions)
    
  4. Double-click the MSI to install it, or see Installing and uninstalling the MSI.

Parameters

Parameter Required Default Description
-SourceFolder Yes Folder whose entire contents (recursively) are packaged.
-ProductName Yes Name used for the install folder, the Start Menu shortcut and the Apps & features entry. Cannot contain \ / : * ? " < > |.
-Version Yes Product version, major.minor.build (e.g. 1.4.2). Limits: major ≤ 255, minor ≤ 255, build ≤ 65535.
-Manufacturer No Current user name Publisher shown in Apps & features.
-ShortcutTarget No The only .exe in the folder root File the Start Menu shortcut points to, relative to -SourceFolder (e.g. bin\App.exe). Required if the folder root has zero or several .exe files.
-UpgradeCode No Derived from ProductName + Manufacturer GUID that ties all versions of the product together. See Versioning and upgrades.
-OutputPath No .\<ProductName>-<Version>.msi Where to write the MSI (spaces are removed from the default file name). An existing file is overwritten.
-Platform No x64 x64 installs to C:\Program Files. x86 installs to C:\Program Files (x86) on 64-bit Windows.
-IconPath No The shortcut target's icon Icon shown in Apps & features: an .ico file, or an .exe/.dll whose first icon is used (all sizes are kept). If the default target has no icon, a warning is printed and Windows shows a generic icon.

Full help is also available from PowerShell:

Get-Help .\MSIInstallerCreator.ps1 -Full

Examples

Basic package, where the folder contains a single .exe:

.\MSIInstallerCreator.ps1 -SourceFolder .\build -ProductName ExampleName -Version 1.0.0 -Manufacturer "Contoso"

Executable in a subfolder, product name with spaces:

.\MSIInstallerCreator.ps1 -SourceFolder C:\out\app -ProductName "My App" -Version 2.1.0 -ShortcutTarget "bin\MyApp.exe"

Installs to C:\Program Files\My App\ with a Start Menu shortcut called My App.

32-bit application, custom output location:

.\MSIInstallerCreator.ps1 -SourceFolder .\build32 -ProductName ExampleName -Version 1.0.0 -Platform x86 -OutputPath .\dist\ExampleName-x86.msi

Custom Apps & features icon:

.\MSIInstallerCreator.ps1 -SourceFolder .\build -ProductName ExampleName -Version 1.0.0 -IconPath .\assets\ExampleName.ico

Explicit UpgradeCode, recommended for products you'll ship long-term:

.\MSIInstallerCreator.ps1 -SourceFolder .\build -ProductName ExampleName -Version 1.1.0 -Manufacturer "Contoso" -UpgradeCode "{6F1B3C2A-9D4E-4F7A-8B21-3C5D7E9F0A12}"

In a build pipeline:

$version = (Get-Item .\build\ExampleName.exe).VersionInfo.ProductVersion
powershell -NoProfile -ExecutionPolicy Bypass -File .\MSIInstallerCreator.ps1 `
    -SourceFolder .\build -ProductName ExampleName -Version $version -Manufacturer "Contoso" `
    -OutputPath ".\artifacts\ExampleName-$version.msi"
if ($LASTEXITCODE -ne 0) { throw "MSI build failed" }

Installing and uninstalling the MSI

The MSI is a standard Windows Installer package, so all the usual msiexec options apply.

Task Command
Install with a progress bar Double-click the .msi, or msiexec /i ExampleName-1.0.0.msi
Install silently (run from an elevated prompt) msiexec /i ExampleName-1.0.0.msi /qn
Install with a basic progress bar and no prompts msiexec /i ExampleName-1.0.0.msi /qb
Install to a different folder msiexec /i ExampleName-1.0.0.msi INSTALLDIR="D:\Apps\ExampleName"
Write a detailed log msiexec /i ExampleName-1.0.0.msi /l*v install.log
Uninstall Apps & features → ExampleName → Uninstall, or msiexec /x ExampleName-1.0.0.msi
Uninstall silently msiexec /x ExampleName-1.0.0.msi /qn
Extract files without installing msiexec /a ExampleName-1.0.0.msi /qn TARGETDIR="C:\temp\extract"

After installation:

  • Files: C:\Program Files\ExampleName\...
  • Shortcut: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\ExampleName.lnk
  • Registration: Apps & features shows ExampleName, its version, publisher and install location.

Silent installs (/qn) can't show a UAC prompt, so run them from an elevated prompt or as SYSTEM (e.g. Intune, SCCM, Group Policy). Otherwise the install fails.

Versioning and upgrades

Windows Installer uses three identifiers. The script manages all of them:

Identifier Changes when How the script handles it
UpgradeCode Never for a given product Derived from ProductName + Manufacturer, or set with -UpgradeCode.
ProductCode Every build New random GUID each build, so every build is a major upgrade.
PackageCode Every build New random GUID each build, as Windows Installer requires.

What happens when a user installs a package while another version with the same UpgradeCode is already installed:

Already installed Installing Result
1.0.0 1.0.1 The old version is removed, then the new one is installed. One entry remains in Apps & features.
1.0.0 1.0.0 (rebuilt) Same as above, so a rebuild of the same version replaces the installed one.
1.0.1 1.0.0 Refused: "A newer version of ExampleName is already installed."

Notes:

  • Keep the UpgradeCode stable. If you rely on the derived default, don't change -ProductName or -Manufacturer between versions, or the new build will install side by side instead of upgrading. To rename a product, pass the original UpgradeCode explicitly with -UpgradeCode. The script prints the UpgradeCode after every build so you can record it.
  • Windows Installer only compares the first three version fields. 1.0.0.1 and 1.0.0.2 count as the same version. Bump at least the build number (1.0.1).
  • x64 and x86 builds are separate products as far as file components go. Don't switch -Platform between versions of the same product.

How it works

The script authors the MSI database directly, in the same way WiX or Visual Studio installer projects do under the hood:

  1. Scans -SourceFolder recursively and assigns each folder and file an MSI identifier. Long names are paired with generated 8.3 short names (SETTIN~1.JSO|settings long name.json) as the MSI format requires.
  2. Compresses all files into product.cab with makecab.exe (LZX compression). Each file is stored in the cabinet under its MSI file key.
  3. Extracts the product icon from the shortcut target (or -IconPath) into a multi-size .ico. It reads the executable's icon resources with Win32 APIs, called through a small C# helper that Add-Type compiles with the compiler built into .NET Framework. The executable is loaded as data only and is never run.
  4. Creates a new MSI database through the WindowsInstaller.Installer COM object, then:
    • creates the required tables with MSI SQL (CREATE TABLE …)
    • inserts rows for directories, components, files, the feature, the shortcut, upgrade rules and the install/admin sequences
    • embeds product.cab in the database's _Streams table
    • writes the Summary Information stream (platform, package code, schema version, compression flags)
    • switches the database to the UTF-8 code page if any name contains non-ASCII characters
  5. Commits the database, moves it to -OutputPath and deletes the temporary working folder.

Because the COM object has no type library PowerShell can bind to, all calls go through late-bound InvokeMember (Invoke-Com in the script).

What's inside the generated MSI

Table Contents
Property ProductName, ProductCode, ProductVersion, Manufacturer, UpgradeCode, ALLUSERS=1, ARPNOMODIFY=1, ARPPRODUCTICON (when an icon is available)
Directory TARGETDIR → ProgramFiles64Folder/ProgramFilesFolder → INSTALLDIR → your subfolders; plus ProgramMenuFolder
Component One component per file, with the file as its key path. Component GUIDs are derived from UpgradeCode + platform + relative path, so they stay the same across builds. One extra component per empty folder.
File Every file with its size, version and language (for versioned binaries such as .exe/.dll), marked compressed
Feature / FeatureComponents A single feature, Main, containing all components
CreateFolder Empty folders, so they're created on install
Media One medium referencing the embedded cabinet #product.cab
Shortcut The Start Menu shortcut (non-advertised; uses the target's own icon)
Upgrade / LaunchCondition Detection of older versions (removed) and newer versions (blocked)
CustomAction Sets ARPINSTALLLOCATION so Apps & features knows the install folder
Icon ProductIcon.ico, the Apps & features icon. Windows Installer caches it in %WINDIR%\Installer\{ProductCode}\.
InstallUISequence / InstallExecuteSequence Standard install actions, with RemoveExistingProducts scheduled before InstallInitialize
AdminUISequence / AdminExecuteSequence Standard actions for administrative installs (msiexec /a)

You can inspect the result with any MSI viewer, such as Orca from the Windows SDK.

Limitations

  • No wizard UI. The package shows only the standard progress bar, with no welcome page, licence page or folder picker. The install folder can still be changed with INSTALLDIR=… on the command line.
  • Per-machine only. Installs for all users into Program Files and needs elevation.
  • One shortcut, in the Start Menu root. There's no desktop shortcut, no Start Menu subfolder and no arguments. The shortcut always shows its target's own icon (-IconPath only affects Apps & features).
  • Files and folders only. No registry entries, services, environment variables, file associations or custom actions.
  • Not code-signed. Users will see an "Unknown publisher" UAC prompt and possibly a SmartScreen warning. You can sign the MSI after building with signtool from the Windows SDK: signtool sign /fd SHA256 /a /tr http://timestamp.digicert.com /td SHA256 ExampleName-1.0.0.msi
  • 2 GB limit on the compressed size (cabinet format limit).
  • Hidden and system files in the source folder are included, so clean the folder before building.
  • No ICE validation is run. The packages install, upgrade and uninstall correctly, but tools such as Orca's validation may report warnings (e.g. the shortcut's key path), which are harmless here.

Troubleshooting

"…cannot be loaded because running scripts is disabled on this system" Run it with powershell -ExecutionPolicy Bypass -File .\MSIInstallerCreator.ps1 …, or allow local scripts once with Set-ExecutionPolicy -Scope CurrentUser RemoteSigned. If you downloaded the script, you may also need Unblock-File .\MSIInstallerCreator.ps1.

"…cannot be loaded. The file … is not digitally signed." (script on a network drive) Under the RemoteSigned execution policy, a script on a network share counts as "remote" if Windows doesn't place the share in the Local intranet zone. Shares reached by IP address (e.g. a drive mapped to \\192.168.1.10\share) and by fully qualified name usually aren't, so the script must be signed to run from them. Unblock-File won't help here, because the file has no download mark. Any of these works:

  • Bypass the policy for one run: powershell -ExecutionPolicy Bypass -File .\MSIInstallerCreator.ps1 …
  • Bypass it for the current PowerShell window: Set-ExecutionPolicy -Scope Process Bypass
  • Copy the script to a local drive and run it from there.
  • Map the share by computer name (\\servername\share) instead of by IP address, or add the server to Internet Options → Security → Local intranet → Sites → Advanced. RemoteSigned then treats the share as local.

"Found N .exe files at the top of SourceFolder; specify -ShortcutTarget." Tell the script which file the shortcut should open, e.g. -ShortcutTarget "ExampleName.exe".

"Version must be at most 255.255.65535" Windows Installer version limits. Use a smaller scheme, e.g. 2026.11.22 won't work but 26.11.22 will.

"makecab failed" The error output from makecab is included in the message. A common cause is a file locked by another process, so close the application that is using it.

Installation fails with error 1603 Install with a log and search it for Return value 3, which marks the action that failed:

msiexec /i ExampleName-1.0.0.msi /l*v install.log

"A newer version of ExampleName is already installed." This is the downgrade protection working. Uninstall the newer version first, or build with a higher -Version.

A new version installs alongside the old one instead of replacing it The UpgradeCode changed, usually because -ProductName or -Manufacturer changed. Rebuild with -UpgradeCode set to the value printed for the earlier version.

License

MIT © 2026 Jimmy Nordström

About

PowerShell script that turns any folder into a Windows Installer (.msi) package with zero dependencies. It uses the built-in Windows Installer API and makecab. Installs to Program Files, adds a Start Menu shortcut and an Apps & features icon, and supports upgrades and clean uninstall.

Topics

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Sponsor this project

Contributors

Languages