- Set up a package workspace with source, package and notes
- Read the product code and other properties from an MSI with Get-ADTMsiTableProperty
- Fill in the $adtSession metadata for a real application
- Write the Install, Uninstall and Repair sections with Start-ADTMsiProcess
- Check the wrapper script for syntax errors before the first run
This lesson turns the raw installation from lesson 1 into a PSADT package. It is the guided version of the 7-Zip walkthrough on the blog: fewer topics, smaller steps, and a checkpoint after each step that confirms the result before the next one starts. The walkthrough also covers file associations, code signing and the handover in more detail; this lesson stays with what a first package needs. Where code differs between the two, this lesson follows the PSADT 4.1.8 template.
The package does four things: install the MSI silently, record the result in the PSADT log, uninstall the same MSI, and repair it on request. Everything else is left for later.
Steps 1 to 7 run on the packaging machine PKG01, which has the PSADT module from lesson 2, the downloaded MSI and an editor. Step 8 runs the finished package on the test VM CL01, reverted to the clean checkpoint psadt-L4-start. The package is built once and only copied to the VM, so every revert of the VM leaves the package untouched.
Step 1: The workspace
A package is easier to maintain when the vendor file, the package and the notes are kept apart. This course uses the following layout; on a real packaging share the same layout sits under a share path.
C:\Lab\Packages\7-Zip\26.06\
├── Source\ original vendor file, never modified
├── Package\ the PSADT package (created in the next step)
└── Notes.md packaging notes for this versionThe commands below assume that the MSI downloaded in lesson 1 is in C:\Lab\Source\ on the packaging machine and that the notes from lesson 1 are in C:\Lab\Notes.md. Adjust both paths if they are stored elsewhere.
# Create the workspace and copy the source file and notes from lesson 1
$root = 'C:\Lab\Packages\7-Zip\26.06'
New-Item -Path "$root\Source" -ItemType Directory -Force | Out-Null
Copy-Item -Path 'C:\Lab\Source\7z2606-x64.msi' -Destination "$root\Source\"
Copy-Item -Path 'C:\Lab\Notes.md' -Destination "$root\Notes.md"Checkpoint 1: Source\7z2606-x64.msi exists, and its SHA-256 hash matches the value in Notes.md and the digest on the GitHub release page from lesson 1:
(Get-FileHash -Path 'C:\Lab\Packages\7-Zip\26.06\Source\7z2606-x64.msi' -Algorithm SHA256).HashStep 2: Create the package and stage the installer
Open a new Windows PowerShell console and allow scripts for this session first, as described in lesson 2 (Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force). Without it, New-ADTTemplate fails on a default Windows client.
# Create the PSADT package folder and stage the installer in Files\
New-ADTTemplate -Destination 'C:\Lab\Packages\7-Zip\26.06' -Name 'Package'
$package = 'C:\Lab\Packages\7-Zip\26.06\Package'
Copy-Item -Path 'C:\Lab\Packages\7-Zip\26.06\Source\7z2606-x64.msi' -Destination "$package\Files\"
Remove-Item -Path "$package\Files\Add Setup Files Here.txt", "$package\SupportFiles\Add Supporting Files Here.txt"New-ADTTemplate places a placeholder text file in Files\ and SupportFiles\; the last line removes them so that the folders hold only real content. If Package\ already exists and is not empty, New-ADTTemplate stops with an error.
-Force does not merge. It deletes the existing Package\ folder, including a wrapper that was already edited, before it creates a new template.
Checkpoint 2: Package\Files\ contains exactly one file, 7z2606-x64.msi. Package\ contains Invoke-AppDeployToolkit.ps1, Invoke-AppDeployToolkit.exe and the folders listed in lesson 2.
Step 3: Read the MSI properties
Before any wrapper code is written, the MSI's own data is read. The values go into the notes and later into the detection rule. Get-ADTMsiTableProperty reads the Property table of an MSI and does not need an open session:
# Read key properties from the MSI's Property table
# (New-ADTTemplate in step 2 has already loaded the module in this console)
$msi = 'C:\Lab\Packages\7-Zip\26.06\Package\Files\7z2606-x64.msi'
$props = Get-ADTMsiTableProperty -LiteralPath $msi
foreach ($name in 'ProductName', 'ProductVersion', 'Manufacturer', 'ProductCode', 'UpgradeCode', 'ALLUSERS') {
$value = if ($props.ContainsKey($name)) { $props[$name] } else { '(not set in Property table)' }
'{0,-15} {1}' -f $name, $value
}What each value is for:
| Property | Used for |
|---|---|
ProductCode | Identifies exactly this MSI build. The standard detection rule and the uninstall target. |
ProductVersion | The version as Windows Installer sees it; compared in detection rules with version checks. |
UpgradeCode | Shared across versions of the product line; used by Windows Installer for major upgrades. |
ProductName | The name in Apps and Features, and part of the MSI log file name (step 5). |
Manufacturer | A sensible value for AppVendor and for the publisher field in the deployment tool. |
ALLUSERS | Whether the MSI installs per machine, per user, or decides at installation time. |
Checkpoint 3: The output shows a ProductCode in the form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}. It is the same GUID that lesson 1 found as PSChildName in the uninstall registry: Windows Installer stores the uninstall entry of an MSI in a subkey named after its product code. Add ProductName, ProductVersion, ProductCode and UpgradeCode to Notes.md.
Files\.
The 7-Zip source code (DOC/7zip.wxs) defines the product name as 7-Zip plus version and edition, and a four-part product version such as 26.06.00.0. The output should show values of that form; the product version does not have to match AppVersion exactly.
ALLUSERS decides the installation context. According to the ALLUSERS reference, an MSI without the property installs per user, 1 means per machine, and 2 lets Windows Installer choose: on current Windows versions it then follows MSIINSTALLPERUSER, and with that property empty it installs per machine when administrator rights are available. The 7-Zip source sets ALLUSERS to 2 and does not set MSIINSTALLPERUSER, so an installation from an elevated process or as SYSTEM is per machine. Checkpoint 6 confirms the actual result: C:\Program Files\7-Zip and an uninstall entry in HKLM. MSI properties in depth are covered in the advanced course.
Step 4: Fill in the metadata
Open Package\Invoke-AppDeployToolkit.ps1 and replace the $adtSession block:
$adtSession = @{
# App variables.
AppVendor = 'Igor Pavlov'
AppName = '7-Zip'
AppVersion = '26.06'
AppArch = 'x64'
AppLang = 'EN'
AppRevision = '01'
AppSuccessExitCodes = @(0)
AppRebootExitCodes = @(1641, 3010)
AppProcessesToClose = @(
@{ Name = '7zFM'; Description = '7-Zip File Manager' }
@{ Name = '7zG'; Description = '7-Zip GUI' }
)
AppScriptVersion = '1.0.0'
AppScriptDate = '2026-11-29'
AppScriptAuthor = 'Packaging Team'
RequireAdmin = $true
# Install Titles (Only set here to override defaults set by the toolkit).
InstallName = ''
InstallTitle = ''
# Script variables.
DeployAppScriptFriendlyName = $MyInvocation.MyCommand.Name
DeployAppScriptParameters = $PSBoundParameters
DeployAppScriptVersion = '4.1.8'
}Notes on the choices:
AppVendormatches theManufacturerfrom step 3. Use the value the MSI actually reports.AppScriptDateis the date on whichNew-ADTTemplatecreated the package; it fills in the current date automatically.AppRevisioncounts package builds of the same application version. When the package is rebuilt for any reason, the revision goes up (01to02), so that logs and reports can tell the builds apart.AppProcessesToClosenames the 7-Zip executables7zFM.exeand7zG.exewithout.exe. The template passes this list toShow-ADTInstallationWelcomein the Pre-Install, Pre-Uninstall and Pre-Repair phases. In an interactive run, the user is asked to close them. InSilentandNonInteractivemode, 4.1.8 closes running listed processes without asking and logsForce closing application(s) [...] without prompting user.The command-line tool7z.exeis left out here, so that scripts using it are not stopped. Closing applications in front of a working user is covered in the advanced course.AppSuccessExitCodesandAppRebootExitCodeskeep their template values.3010and1641are reboot codes defined by Windows Installer.
Checkpoint 4: With these values the install name becomes IgorPavlov_7-Zip_26.06_x64_EN_01. Write the expected log file name into Notes.md: IgorPavlov_7-Zip_26.06_x64_EN_01_PSAppDeployToolkit_Install.log.
Step 5: The Install section
In Install-ADTDeployment, the Pre-Install part of the template already shows the welcome and progress dialogs. Leave it as it is. Add one line in the Install part and adjust the closing prompt in Post-Install. The complete function then reads:
function Install-ADTDeployment
{
[CmdletBinding()]
param
(
)
##================================================
## MARK: Pre-Install
##================================================
$adtSession.InstallPhase = "Pre-$($adtSession.DeploymentType)"
## Show Welcome Message, close processes if specified, allow up to 3 deferrals, verify there is enough disk space to complete the install, and persist the prompt.
$saiwParams = @{
AllowDefer = $true
DeferTimes = 3
CheckDiskSpace = $true
PersistPrompt = $true
}
if ($adtSession.AppProcessesToClose.Count -gt 0)
{
$saiwParams.Add('CloseProcesses', $adtSession.AppProcessesToClose)
}
Show-ADTInstallationWelcome @saiwParams
## Show Progress Message (with the default message).
Show-ADTInstallationProgress
## <Perform Pre-Installation tasks here>
##================================================
## MARK: Install
##================================================
$adtSession.InstallPhase = $adtSession.DeploymentType
## Handle Zero-Config MSI installations.
if ($adtSession.UseDefaultMsi)
{
$ExecuteDefaultMSISplat = @{ Action = $adtSession.DeploymentType; FilePath = $adtSession.DefaultMsiFile }
if ($adtSession.DefaultMstFile)
{
$ExecuteDefaultMSISplat.Add('Transforms', $adtSession.DefaultMstFile)
}
Start-ADTMsiProcess @ExecuteDefaultMSISplat
if ($adtSession.DefaultMspFiles)
{
$adtSession.DefaultMspFiles | Start-ADTMsiProcess -Action Patch
}
}
## <Perform Installation tasks here>
Start-ADTMsiProcess -Action Install -FilePath '7z2606-x64.msi'
##================================================
## MARK: Post-Install
##================================================
$adtSession.InstallPhase = "Post-$($adtSession.DeploymentType)"
## <Perform Post-Installation tasks here>
Write-ADTLogEntry -Message "7-Zip $($adtSession.AppVersion) installation finished."
## Display a message at the end of the install.
if (!$adtSession.UseDefaultMsi)
{
Show-ADTInstallationPrompt -Message "7-Zip $($adtSession.AppVersion) has been installed." -ButtonRightText 'OK' -NoWait
}
}The Zero-Config block stays in place but does nothing, because AppName is set. What Start-ADTMsiProcess does with the one added line, according to its 4.1.8 help and source:
- A bare file name is looked up in
$adtSession.DirFiles, so the line works from any location the deployment tool copies the package to. - The
msiexecarguments come fromConfig\config.psd1:SilentParamsinSilentandNonInteractivemode,InstallParamsotherwise. In 4.1.8 both areREBOOT=ReallySuppress /QN, and logging uses/L*V. The resulting command line ismsiexec.exe /i "<Files>\7z2606-x64.msi" REBOOT=ReallySuppress /QN /L*V "<log file>".REBOOT=ReallySuppresssuppresses all restarts and restart prompts of the installer; a required restart is reported through exit code3010instead. - A verbose MSI log is written to the same folder as the PSADT log. For an installation, its name is built from
ProductNameandProductVersionof the MSI with spaces removed, plus_Install.log; for this MSI, the lab run produced7-Zip26.06(x64edition)_26.06.00.0_Install.log. Add the expected name, built from the step 3 values, toNotes.md. - If the product code of the MSI is already installed, the function logs
The MSI is already installed on this system. Skipping action [Install]...and does nothing. - An exit code outside the success and reboot lists is logged as
Execution failed with exit code [...]and ends the deployment with an error. Lesson 5 shows which exit code the deployment tool then receives.
Extra MSI properties go in -AdditionalArgumentList, for example -AdditionalArgumentList 'PROPERTY=VALUE', or an array such as 'PROP1=A', 'PROP2=B'. -ArgumentList replaces the config.psd1 parameters, including REBOOT=ReallySuppress /QN; the action, the file, transforms and logging are still added. A replacement list therefore has to repeat /QN itself, which is why -ArgumentList is rarely needed.
Show-ADTInstallationPrompt -NoWait shows the closing message without waiting for a click. In Silent and NonInteractive mode, and when no user is signed in, the prompt is skipped and only logged. Deleting the prompt is equally valid for packages that always run silently.
Step 6: The Uninstall and Repair sections
In Uninstall-ADTDeployment, add one line below ## <Perform Uninstallation tasks here>:
## <Perform Uninstallation tasks here>
Start-ADTMsiProcess -Action Uninstall -FilePath '7z2606-x64.msi'With a file path, the function reads the product code from the MSI, checks the uninstall registry for it, and runs msiexec.exe /x with the MSI, so it removes exactly that build. If it is not installed, the function logs The MSI is not installed on this system. Skipping action [Uninstall]... and continues. An equivalent form uses the product code from step 3:
# Alternative: uninstall by product code (replace the GUID with the value read in step 3)
Start-ADTMsiProcess -Action Uninstall -ProductCode '{00000000-0000-0000-0000-000000000000}'In Repair-ADTDeployment, below ## <Perform Repair tasks here>:
## <Perform Repair tasks here>
Start-ADTMsiProcess -Action Repair -FilePath '7z2606-x64.msi'The 4.1.8 default -RepairMode is Reinstall: the function runs msiexec.exe /i again with the install parameters plus REINSTALL=ALL REINSTALLMODE=omus. Microsoft's REINSTALLMODE reference describes omus as the default mode: replace missing or older files, rewrite the machine and user registry entries, and reinstall shortcuts. A repair of a product that is not installed is skipped like an uninstall.
For uninstall and repair, the MSI log name comes from the installed application's uninstall entry, DisplayName and DisplayVersion, plus _Uninstall.log or _Repair.log. For an MSI, Windows Installer fills these from ProductName and ProductVersion, so the names normally match the install log.
-FilePath, or use parameters such as -AddParameters or -Parameters. In 4.1.8, -FilePath accepts only paths ending in .msi or .msp, the product code belongs in -ProductCode (only for actions other than Install), and the parameters are called -AdditionalArgumentList and -ArgumentList. Get-Help Start-ADTMsiProcess -Full shows the exact parameter set of the installed version.
Step 7: Check the syntax
A typing error in the wrapper only shows up when the script runs. The PowerShell parser finds it earlier:
# Parse the wrapper script without running it and list any syntax errors
$path = 'C:\Lab\Packages\7-Zip\26.06\Package\Invoke-AppDeployToolkit.ps1'
$tokens = $null
$errors = $null
[System.Management.Automation.Language.Parser]::ParseFile($path, [ref]$tokens, [ref]$errors) | Out-Null
if ($errors.Count -eq 0) { 'No syntax errors found.' } else { $errors | Select-Object -Property Message, Extent }Checkpoint 5: The output is No syntax errors found. A parser check does not prove that the package works. A misspelled parameter name, for example, is only reported when the line runs. The check removes one class of errors before the first test.
Step 8: A first run
Lesson 5 is about testing in detail. One quick run here confirms that the pieces fit together.
Apply the checkpoint psadt-L4-start of CL01 and copy the Package folder from PKG01 to the same path on the VM, C:\Lab\Packages\7-Zip\26.06\Package. The VM needs neither the PSADT module nor a changed execution policy: the package carries its own module, and the launcher starts PowerShell with -ExecutionPolicy Bypass. Open Windows PowerShell as administrator on the VM:
# First silent install from an elevated Windows PowerShell console
Set-Location -Path 'C:\Lab\Packages\7-Zip\26.06\Package'
$run = Start-Process -FilePath '.\Invoke-AppDeployToolkit.exe' -ArgumentList '-DeploymentType Install -DeployMode Silent' -Wait -PassThru
"Exit code: $($run.ExitCode)"
Test-Path -Path 'C:\Program Files\7-Zip\7zFM.exe'Invoke-AppDeployToolkit.exe is a Windows application, not a console program, so PowerShell does not wait for it on its own. Start-Process -Wait -PassThru waits and returns the exit code.
Checkpoint 6: The exit code is 0, Test-Path returns True, the uninstall registry query from lesson 1 shows the product code from step 3, and C:\Windows\Logs\Software holds the PSADT log with the name noted in checkpoint 4 next to the MSI log with the name noted in step 5. The PSADT log contains Executing MSI action [Install]... and Execution completed successfully with exit code [0].
Common mistakes
| Symptom | Cause | Fix |
|---|---|---|
The PSADT log shows The MSI is already installed on this system. Skipping action [Install]..., and nothing is installed | The product code of the MSI is already installed on the test VM, for example from an earlier test | Apply the clean checkpoint psadt-L4-start before every test |
The wrapper stops with a parameter error at the Start-ADTMsiProcess line | 3.x syntax: a product code in -FilePath, or -Parameters / -AddParameters. In 4.1 the parameters are -FilePath ("the MSI/MSP file"), -ProductCode, -ArgumentList and -AdditionalArgumentList | Use the 4.1 names; Get-Help Start-ADTMsiProcess -Full shows the parameter set of the installed version |
| An extra MSI property removes the silent switch or the restart suppression | -ArgumentList "Overrides the default parameters specified in the config.psd1 file" | Pass extra properties with -AdditionalArgumentList, which "Adds additional parameters to the default set" |
The first run on CL01 ends with exit code 60008 | The console is not elevated; the launcher does not elevate itself | Start Windows PowerShell as administrator on CL01 |
Try it
Steps 1 to 8 above are the exercise. This section adds the start state, an uninstall test and the end state.
On the Hyper-V host, apply the checkpoint
psadt-L4-startofCL01and start the VM if it is off. If the checkpoint does not exist yet, apply the clean checkpointpsadt-L3-start(notpsadt-L3-end) and take it:Checkpoint-VM -Name CL01 -SnapshotName psadt-L4-start. Other hypervisors: the equivalent snapshot. Expected:CL01is clean and holds no tools and no 7-Zip. Check:Get-VMCheckpoint -VMName CL01listspsadt-L4-start.On
PKG01, work through steps 1 to 7 of this lesson, starting in a Windows PowerShell console with scripts allowed for the session (lesson 2). Expected: checkpoints 1 to 5 are met. Check: the parser command from step 7 printsNo syntax errors found.Run step 8 on
CL01: copy thePackagefolder and run a silent install from an elevated console. Expected: checkpoint 6 is met: exit code0,7zFM.exeexists, andC:\Windows\Logs\SoftwareholdsIgorPavlov_7-Zip_26.06_x64_EN_01_PSAppDeployToolkit_Install.logand one MSI log ending in_Install.log. Check:Test-Path -Path 'C:\Program Files\7-Zip\7zFM.exe'returnsTrue.In the same console, run a silent uninstall:
powershell$run = Start-Process -FilePath '.\Invoke-AppDeployToolkit.exe' -ArgumentList '-DeploymentType Uninstall -DeployMode Silent' -Wait -PassThru "Exit code: $($run.ExitCode)" Test-Path -Path 'C:\Program Files\7-Zip\7zFM.exe'Expected:
Exit code: 0andFalse.C:\Windows\Logs\Softwarenow also holdsIgorPavlov_7-Zip_26.06_x64_EN_01_PSAppDeployToolkit_Uninstall.logand one MSI log ending in_Uninstall.log. Check:Get-ChildItem -Path 'C:\Windows\Logs\Software' -Filter '*_Uninstall.log'lists both files.On the host, revert
CL01topsadt-L4-start, then take the checkpointpsadt-L4-end. The package onPKG01is the copy that lesson 5 starts from. Expected:CL01is clean, andNotes.mdonPKG01lists source, hash, product code, upgrade code and the expected log names. Check:Get-Content -Path 'C:\Lab\Packages\7-Zip\26.06\Notes.md'onPKG01.
Check your understanding
- Why does the wrapper call
Start-ADTMsiProcess -FilePath '7z2606-x64.msi'without a folder path?
Answer
A bare file name is looked up in $adtSession.DirFiles, the Files\ folder of the running package. The package therefore works wherever the deployment tool places it, for example in the Configuration Manager client cache or the Intune content folder.
- Where should the product code for detection and uninstall come from?
Answer
From the MSI that is actually in Files\, read with Get-ADTMsiTableProperty, Orca or the uninstall registry after a test installation. A product code from another source may belong to a different build.
- What happens when the Install section runs on a device where this exact MSI is already installed?
Answer
Start-ADTMsiProcess finds the product code already installed, logs The MSI is already installed on this system. Skipping action [Install]... and skips the installation. The deployment still completes.
- Which parameter adds an MSI property without replacing the default msiexec arguments?
Answer
-AdditionalArgumentList. -ArgumentList replaces the defaults from config.psd1, including REBOOT=ReallySuppress /QN.
- When does
AppRevisionchange?
Answer
Every time the package is rebuilt for the same application version, for example after a fix in the wrapper. The new revision changes the install name and therefore the log file names, so the builds can be told apart.
- 7-Zip File Manager is open when the package runs with
-DeployMode Silent. What happens?
Answer
Show-ADTInstallationWelcome in the Pre-Install phase closes 7zFM without asking, because the session is silent, and logs Force closing application(s) [...] without prompting user. Unsaved work in that window is lost.
Summary
- Source, package and notes live in separate places; the source file is hashed and never modified. The package is built on the packaging machine and copied to the test VM.
- The product code and other MSI properties are read from the MSI in
Files\before the wrapper is written. The 7-Zip MSI setsALLUSERSto2and installs per machine from an elevated process. - One
Start-ADTMsiProcessline per deployment type installs, uninstalls or repairs the MSI, withREBOOT=ReallySuppress /QN, a verbose log and exit code handling from the toolkit. - In 4.1.8 the parameters are
-FilePathor-ProductCode,-AdditionalArgumentListand-ArgumentList. - In
Silentmode, listed processes are closed without asking and the closing prompt is skipped. - A parser check and one silent run confirm the package before systematic testing starts.
Sources
- PSAppDeployToolkit 4.1 — Start-ADTMsiProcess — https://psappdeploytoolkit.com/docs/4.1.x/reference/functions/Start-ADTMsiProcess (4.1.x, checked 2026-11-30)
- PSAppDeployToolkit 4.1 — Installing applications — https://psappdeploytoolkit.com/docs/4.1.x/usage/installing-applications (4.1.x)
- PSAppDeployToolkit 4.1 — Get-ADTMsiTableProperty — https://psappdeploytoolkit.com/docs/4.1.x/reference/functions/Get-ADTMsiTableProperty (4.1.x)
- PSAppDeployToolkit 4.1 — Invoke-AppDeployToolkit — https://psappdeploytoolkit.com/docs/4.1.x/deployment-concepts/invoke-appdeploytoolkit (4.1.x, checked 2026-11-30)
- Uninstall registry key — https://learn.microsoft.com/en-us/windows/win32/msi/uninstall-registry-key (link from the lesson text; to be checked in stage 7)
- ALLUSERS property — https://learn.microsoft.com/en-us/windows/win32/msi/allusers (link from the lesson text)
- REBOOT property — https://learn.microsoft.com/en-us/windows/win32/msi/reboot (link from the lesson text)
- REINSTALLMODE property — https://learn.microsoft.com/en-us/windows/win32/msi/reinstallmode (link from the lesson text)
- 7-Zip source code,
DOC/7zip.wxs— https://github.com/ip7z/7zip (version 26.06)