### Full Installer Script Example Source: https://github.com/ironmansoftware/psmsi/blob/main/README.md A complete script to create an MSI installer including nested directories and files, outputting to a specified directory. This script generates WXS, WXSOBJ, and MSI files. ```powershell New-Installer -ProductName "My First Product" -UpgradeCode '1a73a1be-50e6-4e92-af03-586f4a9d9e82' -Content { New-InstallerDirectory -PredefinedDirectory "LocalAppDataFolder" -Content { New-InstallerDirectory -DirectoryName "My First Product" -Content { New-InstallerFile -Source .\license.txt } } } -OutputDirectory (Join-Path $PSScriptRoot "output") ``` -------------------------------- ### Create All Users Installation Source: https://github.com/ironmansoftware/psmsi/blob/main/README.md Configures the installer for 'All Users' (PerMachine) installation by using the -RequiresElevation parameter. This example installs to the Program Files folder. ```powershell New-Installer -ProductName "My First Product" -UpgradeCode '1a73a1be-50e6-4e92-af03-586f4a9d9e82' -Content { New-InstallerDirectory -PredefinedDirectory "ProgramFilesFolder" -Content { New-InstallerDirectory -DirectoryName "My First Product" -Content { New-InstallerFile -Source .\license.txt } } } -OutputDirectory (Join-Path $PSScriptRoot "output") -RequiresElevation ``` -------------------------------- ### New-InstallerDirectory Source: https://context7.com/ironmansoftware/psmsi/llms.txt Defines installation directories, supporting predefined system paths and custom subdirectories. The -Configurable parameter allows users to select the installation path during setup. ```APIDOC ## New-InstallerDirectory — Define Installation Directories Creates either a predefined system directory (e.g., `ProgramFilesFolder`, `AppDataFolder`, `DesktopFolder`) or a custom subdirectory within it. Directories can be nested to any depth. Adding `-Configurable` lets the end user choose the installation path during setup. ```powershell # Predefined root + custom subdirectory + user-selectable leaf directory New-Installer \ -ProductName "MyApp" \ -UpgradeCode 'a1b2c3d4-0000-0000-0000-000000000002' \ -OutputDirectory (Join-Path $PSScriptRoot "output") \ -Content { New-InstallerDirectory -PredefinedDirectoryName "ProgramFilesFolder" -Content { # Fixed parent folder New-InstallerDirectory -DirectoryName "Acme" -Content { # User can change this path during install New-InstallerDirectory -DirectoryName "MyApp" -Configurable -Content { New-InstallerFile -Source .\app.exe New-InstallerFile -Source .\readme.txt } } } } # Valid PredefinedDirectoryName values include: # AdminToolsFolder, AppDataFolder, CommonAppDataFolder, CommonFilesFolder, # CommonFiles64Folder, DesktopFolder, FavoritesFolder, FontsFolder, # LocalAppDataFolder, MyPicturesFolder, PersonalFolder, ProgramFilesFolder, # ProgramFiles64Folder, ProgramMenuFolder, SendToFolder, StartMenuFolder, # StartupFolder, SystemFolder, System64Folder, TemplateFolder, WindowsFolder ``` ``` -------------------------------- ### Create Configurable Directory Source: https://github.com/ironmansoftware/psmsi/blob/main/README.md Use `New-InstallerDirectory` with the `Configurable` parameter to allow users to select the installation directory during setup. This is useful for custom installation paths. ```powershell New-InstallerDirectory -DirectoryName "My First Product" -Content { New-InstallerFile -Source .\license.txt } -Configurable ``` -------------------------------- ### Create Basic Installer Source: https://github.com/ironmansoftware/psmsi/blob/main/README.md Generates a basic MSI installer. Requires ProductName and a unique UpgradeCode. The Content parameter defines the installation structure. ```powershell New-Installer -ProductName "My First Product" -UpgradeCode '1a73a1be-50e6-4e92-af03-586f4a9d9e82' ``` -------------------------------- ### Install PSMSI Module Source: https://github.com/ironmansoftware/psmsi/blob/main/README.md Installs the PSMSI module from the PowerShell Gallery. This is the first step to start creating installers. ```powershell Install-Module PSMSI ``` -------------------------------- ### New-InstallerShortcut Source: https://context7.com/ironmansoftware/psmsi/llms.txt Defines shortcuts for desktop or start menu integration. Shortcuts can reference installed files by their Id or directories by DirectoryId and support customization of name, icon, arguments, and window state. ```APIDOC ## New-InstallerShortcut — Create Desktop or Start Menu Shortcuts Defines a shortcut inside any directory (typically `DesktopFolder` or `StartMenuFolder`). References an installed file by its `Id` or a directory by `DirectoryId`. Supports custom icon, display name, arguments, window state, and working directory. ```powershell New-Installer \ -ProductName "MyApp" \ -UpgradeCode 'a1b2c3d4-0000-0000-0000-000000000003' \ -OutputDirectory (Join-Path $PSScriptRoot "output") \ -RequiresElevation \ -Content { # Install the application New-InstallerDirectory -PredefinedDirectoryName "ProgramFilesFolder" -Content { New-InstallerDirectory -DirectoryName "MyApp" -Id "InstallDir" -Content { New-InstallerFile -Source .\app.exe -Id "MainExe" } } # Desktop shortcut pointing to MainExe, working dir = InstallDir New-InstallerDirectory -PredefinedDirectoryName "DesktopFolder" -Content { New-InstallerShortcut \ -Name "Launch MyApp" \ -FileId "MainExe" \ -Description "Opens MyApp" \ -IconPath ".\assets\app.ico" \ -Arguments "--gui" \ -Show "normal" \ -WorkingDirectoryId "InstallDir" } # Start Menu shortcut New-InstallerDirectory -PredefinedDirectoryName "StartMenuFolder" -Content { New-InstallerShortcut -Name "MyApp" -FileId "MainExe" } } ``` ``` -------------------------------- ### Create Shortcuts with New-InstallerShortcut Source: https://context7.com/ironmansoftware/psmsi/llms.txt Define shortcuts for the desktop or Start Menu using New-InstallerShortcut. It references installed files by Id or directories by DirectoryId and supports custom icons, display names, arguments, and more. ```powershell New-Installer ` -ProductName "MyApp" ` -UpgradeCode 'a1b2c3d4-0000-0000-0000-000000000003' ` -OutputDirectory (Join-Path $PSScriptRoot "output") ` -RequiresElevation ` -Content { # Install the application New-InstallerDirectory -PredefinedDirectoryName "ProgramFilesFolder" -Content { New-InstallerDirectory -DirectoryName "MyApp" -Id "InstallDir" -Content { New-InstallerFile -Source .\app.exe -Id "MainExe" } } # Desktop shortcut pointing to MainExe, working dir = InstallDir New-InstallerDirectory -PredefinedDirectoryName "DesktopFolder" -Content { New-InstallerShortcut ` -Name "Launch MyApp" ` -FileId "MainExe" ` -Description "Opens MyApp" ` -IconPath ".\assets\app.ico" ` -Arguments "--gui" ` -Show "normal" ` -WorkingDirectoryId "InstallDir" } # Start Menu shortcut New-InstallerDirectory -PredefinedDirectoryName "StartMenuFolder" -Content { New-InstallerShortcut -Name "MyApp" -FileId "MainExe" } } ``` -------------------------------- ### Create Installer with Version Source: https://github.com/ironmansoftware/psmsi/blob/main/README.md Use `New-Installer` to create a new installer package. The `Version` parameter specifies the installer version, which can be incremented for upgrades while keeping the `UpgradeCode` the same. Defaults to 1.0. ```powershell New-Installer -ProductName "My First Product" -UpgradeCode '1a73a1be-50e6-4e92-af03-586f4a9d9e82' -Content { New-InstallerDirectory -PredefinedDirectory "ProgramFilesFolder" -Content { New-InstallerDirectory -DirectoryName "My First Product" -Content { New-InstallerFile -Source .\license.txt } } } -OutputDirectory (Join-Path $PSScriptRoot "output") -Version 2.0 ``` -------------------------------- ### Create Installer User Interface Source: https://github.com/ironmansoftware/psmsi/blob/main/README.md Use this to define a custom user interface for your installer, specifying paths to the EULA and banner/welcome images. Ensure the specified files exist at the provided paths. ```powershell $UserInterface = New-InstallerUserInterface -Eula (Join-Path $PSScriptRoot 'eula.rtf') -TopBanner (Join-Path $PSScriptRoot "banner.png") -Welcome (Join-Path $PSScriptRoot "welcome.png") ``` -------------------------------- ### Define Custom Action for Installation Source: https://github.com/ironmansoftware/psmsi/blob/main/README.md Use `New-InstallerCustomAction` to specify a script to run during installation. The `FileId` parameter links to the script included via `New-InstallerFile`. Custom actions must be passed to `New-Installer` via the `CustomAction` parameter, not the `Content` block. ```powershell New-InstallerCustomAction -FileId 'CustomAction' -RunOnInstall ``` -------------------------------- ### Install and Import PSMSI Module Source: https://context7.com/ironmansoftware/psmsi/llms.txt Install the PSMSI module from the PowerShell Gallery and then import it into your current session to use its cmdlets. ```powershell Install-Module PSMSI Import-Module PSMSI ``` -------------------------------- ### Define Installation Root Directory Source: https://github.com/ironmansoftware/psmsi/blob/main/README.md Specifies a predefined root directory for installation on the end-user's machine, such as LocalAppDataFolder. ```powershell New-InstallerDirectory -PredefinedDirectory "LocalAppDataFolder" ``` -------------------------------- ### Branded Installer UI with New-InstallerUserInterface Source: https://context7.com/ironmansoftware/psmsi/llms.txt Customize the installer's user interface using New-InstallerUserInterface. This cmdlet allows for EULA, banner images, and background images. Image dimensions are validated, and warnings are issued for non-recommended sizes. ```powershell # Recommended image dimensions: # TopBanner: 493 x 58 px # WelcomeAndCompletionBackground: 493 x 312 px # ExclamationIcon / InformationIcon: 32 x 32 px # NewIcon / UpIcon: 16 x 16 px $ui = New-InstallerUserInterface ` -Eula (Join-Path $PSScriptRoot "eula.rtf") ` -TopBanner (Join-Path $PSScriptRoot "banner.png") ` -WelcomeAndCompletionBackground (Join-Path $PSScriptRoot "welcome.png") ` -ExitDialogText "Thank you for installing MyApp!" New-Installer ` -ProductName "MyApp" ` -UpgradeCode 'a1b2c3d4-0000-0000-0000-000000000005' ` -OutputDirectory (Join-Path $PSScriptRoot "output") ` -UserInterface $ui ` -Content { New-InstallerDirectory -PredefinedDirectoryName "ProgramFilesFolder" -Content { New-InstallerDirectory -DirectoryName "MyApp" -Content { New-InstallerFile -Source . } } } ``` -------------------------------- ### Include File in Installer Source: https://github.com/ironmansoftware/psmsi/blob/main/README.md Adds a file to the installer package. The Source parameter points to the local file to be included. ```powershell New-InstallerFile -Source .\MyTextFile.txt ``` -------------------------------- ### Include File in Directory Source: https://github.com/ironmansoftware/psmsi/blob/main/README.md Use `New-InstallerFile` within the `Content` block of `New-InstallerDirectory` to include files in the installer. The `Source` parameter specifies the file's current location. ```powershell New-InstallerDirectory -DirectoryName "My First Product" -Content { New-InstallerFile -Source .\license.txt } ``` -------------------------------- ### New-InstallerFile Source: https://context7.com/ironmansoftware/psmsi/llms.txt Specifies a file to be included in the installer package. The Source parameter points to the file on the build machine, and an optional Id can be used for referencing by other cmdlets. ```APIDOC ## New-InstallerFile — Include Files in the Installer Specifies a file to bundle into the MSI. The `Source` parameter is the path to the file on the build machine. An optional `Id` string allows other cmdlets (shortcuts, custom actions) to reference the file. ```powershell # File without explicit ID (ID auto-generated) New-InstallerFile -Source .\app.exe # File with explicit ID — required when referenced by shortcuts or custom actions New-InstallerFile -Source .\app.exe -Id "MainExe" New-InstallerFile -Source .\setup.ps1 -Id "SetupScript" New-InstallerFile -Source .\license.txt -Id "LicenseFile" ``` ``` -------------------------------- ### Per-Machine MSI Installation with Elevation Source: https://context7.com/ironmansoftware/psmsi/llms.txt Adds `-RequiresElevation` to switch the install scope to `PerMachine`, targeting system-wide directories and prompting for UAC elevation. This is used for all-users installations. ```powershell New-Installer \ -ProductName "My First Product" \ -UpgradeCode '1a73a1be-50e6-4e92-af03-586f4a9d9e82' \ -Version 2.0 \ -OutputDirectory (Join-Path $PSScriptRoot "output") \ -RequiresElevation \ -Content { New-InstallerDirectory -PredefinedDirectoryName "ProgramFilesFolder" -Content { New-InstallerDirectory -DirectoryName "My First Product" -Content { New-InstallerFile -Source .\app.exe New-InstallerFile -Source .\app.config } } } ``` -------------------------------- ### Run PowerShell Scripts on Install/Uninstall with New-InstallerCustomAction Source: https://context7.com/ironmansoftware/psmsi/llms.txt Use New-InstallerCustomAction to bundle and run PowerShell scripts during installation or uninstallation. The -CheckReturnValue parameter ensures the installation fails if the script exits with a non-zero code. Arguments can be passed to the script using -Arguments and -ScriptArguments. ```powershell $customScript = Join-Path $PSScriptRoot 'postinstall.ps1' New-Installer ` -ProductName "MyApp" ` -UpgradeCode 'a1b2c3d4-0000-0000-0000-000000000004' ` -OutputDirectory (Join-Path $PSScriptRoot "output") ` -Content { New-InstallerDirectory -PredefinedDirectoryName "ProgramFilesFolder" -Content { New-InstallerDirectory -DirectoryName "MyApp" -Content { New-InstallerFile -Source . # Bundle the script and assign an ID for the custom action New-InstallerFile -Source $customScript -Id "PostInstall" } } } ` -CustomAction @( # Runs postinstall.ps1 after install, fails installer on error New-InstallerCustomAction ` -FileId "PostInstall" ` -RunOnInstall ` -CheckReturnValue ` -Arguments "-NoProfile -ExecutionPolicy Bypass" ` -ScriptArguments "-Mode Production" # Separate action that runs on uninstall New-InstallerCustomAction ` -FileId "PostInstall" ` -RunOnUninstall ) ``` -------------------------------- ### Include Files in the Installer with New-InstallerFile Source: https://context7.com/ironmansoftware/psmsi/llms.txt Specify files to bundle into the MSI using New-InstallerFile. The Source parameter points to the file on the build machine. An optional Id allows other cmdlets to reference the file. ```powershell # File without explicit ID (ID auto-generated) New-InstallerFile -Source .\app.exe ``` ```powershell # File with explicit ID — required when referenced by shortcuts or custom actions New-InstallerFile -Source .\app.exe -Id "MainExe" New-InstallerFile -Source .\setup.ps1 -Id "SetupScript" New-InstallerFile -Source .\license.txt -Id "LicenseFile" ``` -------------------------------- ### Define File with ID for Shortcut Source: https://github.com/ironmansoftware/psmsi/blob/main/README.md Assign an `Id` to a file using `New-InstallerFile` when you intend to reference it later for creating shortcuts or other installer elements. ```powershell New-InstallerFile -Source .\MyTextFile.txt -Id "myTestFile" ``` -------------------------------- ### Set Add/Remove Programs Icon Source: https://github.com/ironmansoftware/psmsi/blob/main/README.md Specifies a custom icon file to be displayed in the Add/Remove Programs control panel for the installed application. ```powershell New-Installer -Product "My First Product" -UpgradeCode '1a73a1be-50e6-4e92-af03-586f4a9d9e82' -Content { New-InstallerDirectory -PredefinedDirectory "ProgramFilesFolder" -Content { New-InstallerDirectory -DirectoryName "My First Product" -Content { New-InstallerFile -Source .\license.txt } } } -OutputDirectory (Join-Path $PSScriptRoot "output") -AddRemoveProgramsIcon "icon.ico" ``` -------------------------------- ### Define Nested Installation Directory Source: https://github.com/ironmansoftware/psmsi/blob/main/README.md Creates a nested directory within the specified root directory. This directory will be created if it doesn't exist and removed on uninstall. ```powershell New-InstallerDirectory -DirectoryName "My First Product" ``` -------------------------------- ### Include Custom Action Script File Source: https://github.com/ironmansoftware/psmsi/blob/main/README.md Use `New-InstallerFile` to include a PowerShell script as a file within the installer package. The `Id` parameter is used to reference this script when defining a custom action. ```powershell New-InstallerFile -Source .\myCustomAction.ps1 -Id 'CustomAction' ``` -------------------------------- ### Target Architecture for MSI Package Source: https://context7.com/ironmansoftware/psmsi/llms.txt Controls the installer's target platform using the `-Platform` parameter. Accepted values include `x86`, `x64`, `ia64`, `arm`, `intel`, `intel64`. Defaults to `x86`. ```powershell New-Installer \ -ProductName "My 64-bit Product" \ -UpgradeCode 'a1b2c3d4-0000-0000-0000-000000000001' \ -Platform "x64" \ -OutputDirectory (Join-Path $PSScriptRoot "output") \ -Content { New-InstallerDirectory -PredefinedDirectoryName "ProgramFiles64Folder" -Content { New-InstallerDirectory -DirectoryName "My 64-bit Product" -Content { New-InstallerFile -Source .\app64.exe } } } ``` -------------------------------- ### Create Shortcut on Desktop Source: https://github.com/ironmansoftware/psmsi/blob/main/README.md Use `New-InstallerShortcut` within a directory definition (e.g., `DesktopFolder`) to create a shortcut. Reference the target file using its `FileId`. ```powershell New-InstallerDirectory -PredefinedDirectory "DesktopFolder" -Content { New-InstallerShortcut -Name "My Test File" -FileId "myTestFile" } ``` -------------------------------- ### Create Minimal MSI Package Source: https://context7.com/ironmansoftware/psmsi/llms.txt Orchestrates MSI creation with essential product metadata and a content script block defining the directory and file structure. The `UpgradeCode` must be constant across versions for upgrades to work. ```powershell # Minimal installer — installs license.txt to %LOCALAPPDATA%\My First Product\ New-Installer \ -ProductName "My First Product" \ -UpgradeCode '1a73a1be-50e6-4e92-af03-586f4a9d9e82' \ -Version 1.0 \ -Manufacturer "Acme Corp" \ -Description "My First Product installer" \ -HelpLink "https://example.com/help" \ -AboutLink "https://example.com/about" \ -OutputDirectory (Join-Path $PSScriptRoot "output") \ -Content { New-InstallerDirectory -PredefinedDirectoryName "LocalAppDataFolder" -Content { New-InstallerDirectory -DirectoryName "My First Product" -Content { New-InstallerFile -Source .\license.txt } } } # Output (in ./output/): # My First Product.1.0.x86.wxs # My First Product.1.0.x86.wxsobj # My First Product.1.0.x86.msi <-- distribute this file ``` -------------------------------- ### Set Shortcut Working Directory Source: https://github.com/ironmansoftware/psmsi/blob/main/README.md Specify the `WorkingDirectoryId` in `New-InstallerShortcut` to set the working directory for the shortcut. This ID should correspond to the `Id` of a `New-InstallerDirectory`. ```powershell New-Installer -ProductName "MyImage" -UpgradeCode (New-Guid) -Version 1.0.0 -Content { New-InstallerDirectory -PredefinedDirectoryName ProgramFilesFolder -Content { New-InstallerDirectory -DirectoryName 'MyDir' -Id 'MyDir' -Content { New-InstallerFile -Id 'Image' -Source 'services.png' } } New-InstallerDirectory -PredefinedDirectoryName DesktopFolder -Content { New-InstallerShortcut -Name 'Test' -FileId 'Image' -WorkingDirectoryId 'MyDir' } } -OutputDirectory .\installer -RequiresElevation ``` -------------------------------- ### Define Upgrade Code for Upgrades Source: https://github.com/ironmansoftware/psmsi/blob/main/README.md Ensures successful upgrades by defining a static UpgradeCode for the product. This code should remain consistent across different versions of the same product. ```powershell New-Installer -ProductName "My First Product" -UpgradeCode '1a73a1be-50e6-4e92-af03-586f4a9d9e82' -Content { New-InstallerDirectory -PredefinedDirectory "ProgramFilesFolder" -Content { New-InstallerDirectory -DirectoryName "My First Product" -Content { New-InstallerFile -Source .\license.txt } } } -OutputDirectory (Join-Path $PSScriptRoot "output") ``` -------------------------------- ### Custom ARP Icon for MSI Package Source: https://context7.com/ironmansoftware/psmsi/llms.txt Sets a custom icon for the product that will be displayed in Windows "Add or Remove Programs" or "Apps & features" using the `-AddRemoveProgramsIcon` parameter. ```powershell New-Installer \ -ProductName "My First Product" \ -UpgradeCode '1a73a1be-50e6-4e92-af03-586f4a9d9e82' \ -AddRemoveProgramsIcon ".\assets\app.ico" \ -OutputDirectory (Join-Path $PSScriptRoot "output") \ -Content { New-InstallerDirectory -PredefinedDirectoryName "ProgramFilesFolder" -Content { New-InstallerDirectory -DirectoryName "My First Product" -Content { New-InstallerFile -Source .\app.exe } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.