Skip to main content

Run PowerShell Script

Use this predefined action to run custom PowerShell during installation or uninstallation when standard MSI tables are not enough.

The working directory is typically C:\Windows\System32, so use absolute paths when the script depends on specific files or folders.

Master Packager Advanced Editor - Predefined Custom Actions - Run PowerShell Script

note

Return the correct exit code from the script. 0 indicates success. Any other exit code causes the MSI installation to fail. You can also write to standard output to include messages in the installation log.

When to Use It

Use this action for tasks such as:

  • File management — Create or delete files.
  • Permissions — Adjust file or folder permissions.
  • Registry changes — Add, update, or remove registry keys.
  • Environment configuration — Set environment variables.
  • Custom logic — Handle installation tasks that standard MSI tables cannot express directly.

Fields

FieldDescription
Action NameIdentifies the predefined action in your project.
PowerShell codeLets you browse to an existing .ps1 file or open the editor to write or paste the script directly.
PS Script PreviewShows the script content so you can review it before saving the action.

Script Header Example

Use the following header format:

<#
.DESCRIPTION
This Custom Action can be used to run PowerShell scripts.
Use exit codes for error handling.

.EXAMPLE
Exit 1
#>

Steps

  1. Open the MSI or MST in Master Packager.
  2. In the left pane, select Custom Actions.
  3. Open the Predefined Actions tab.
  4. Click Add New Predefined Action and select Run PowerShell Script.
  5. Enter a value in Action Name.
  6. Add the script by browsing to a .ps1 file or by editing the code inline.
  7. Review the content in PS Script Preview.
tip

Test the script outside the MSI first, especially if it will run under SYSTEM context.