A Wix Extension for running PowerShell scripts
All ready to add to an existing Wix project. Grab the latest version from https://www.nuget.org/packages/PowerShellWixExtension/
- Add a reference to the PowerShellWixExtension.dll in your Wix Setup Project (NuGet package recommended)
- Add namespace to .wxs file
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:powershell="http://schemas.gardiner.net.au/PowerShellWixExtensionSchema">
- To execute a .ps1 file that ships with the project
<powershell:File Id="PSFile1" File="[#TestPs1]" Arguments=""First Argument" 2"/>
- To execute inline script use
<powershell:Script Id="Script2">
<![CDATA[
# Write-Host "Number 2";
for ($i = 1; $i -le 100; $i++)
{
Write-Progress -Activity "Activity" -Status "Status $i% complete" -CurrentOperation "Operation $i" -PercentComplete $i
Start-Sleep -Milliseconds 5
}
]]>
</powershell:Script>
You can customise when a set of scripts are run by adding your own element inside your element. eg.
<InstallExecuteSequence>
<Custom Action="PowerShellScriptsDeferred" After="RegisterUser">NOT Installed</Custom>
</InstallExecuteSequence>
The four defined actions are:
PowerShellScriptsDeferred
PowerShellScriptsElevatedDeferred
PowerShellFilesDeferred
PowerShellFilesElevatedDeferred
- Be aware that if your inline script uses square brackets [ ], you'll need to escape them like [\[] [\]] otherwise they will be interpreted as MSI properties (unless that is what you wanted!)