msix_scripts
napt.build.msix_scripts
MSIX detection and requirements script generation for Intune Win32 apps.
This module generates PowerShell detection and requirements scripts for
MSIX packages deployed as Intune Win32 apps. Unlike MSI/EXE installers
that use registry-based detection, MSIX scripts query the AppX package
database. The query used depends on install_scope:
"system"(default): QueriesGet-AppxProvisionedPackage -Onlinefor provisioned (all-users) packages."user": QueriesGet-AppxPackage -Name <identity_name>for per-user packages.
For system-scope scripts, Version and Architecture are parsed from
PackageName (the package full name) rather than read from object
properties. The package full name format is
Name_Version_Architecture_ResourceId_PublisherId, where underscore is
the structural delimiter. The MSIX spec
(https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/package-identity-overview)
explicitly prohibits underscores in all five components, so splitting on
_ is safe by design. Reading Architecture directly from the object
returns an integer enum value (e.g. 11 for neutral) that requires a
separate mapping step; parsing from PackageName yields the canonical
string form directly.
Detection Logic
- Queries the appropriate AppX store for the package identity
- Compares installed version against expected version
- Supports exact match or minimum version comparison
- Exits 0 if detected, 1 if not detected
Requirements Logic
- Queries the appropriate AppX store for the package identity
- If installed version < target version: outputs "Required"
- Otherwise: outputs nothing
- Always exits 0 so Intune can evaluate STDOUT
Logging
- Primary (System): C:\ProgramData\Microsoft\IntuneManagementExtension\Logs\NAPTDetections.log
- Primary (User): C:\ProgramData\Microsoft\IntuneManagementExtension\Logs\NAPTDetectionsUser.log
- Fallback locations mirror the registry-based scripts
- Format: CMTrace for compatibility with Intune diagnostics
Example
Generate MSIX detection script:
from pathlib import Path
from napt.build.msix_scripts import (
MSIXDetectionConfig,
generate_msix_detection_script,
)
config = MSIXDetectionConfig(
identity_name="com.tinyspeck.slackdesktop",
version="4.49.81.0",
)
script_path = generate_msix_detection_script(
config=config,
output_path=Path("builds/slack/4.49.81.0/Slack-4.49.81.0-Detection.ps1"),
)
Note
Detection and requirements scripts are saved as siblings to the packagefiles directory to prevent them from being included in the .intunewin package.
MSIXDetectionConfig
dataclass
Configuration for MSIX detection script generation.
Attributes:
| Name | Type | Description |
|---|---|---|
identity_name |
str
|
Package identity name for AppX package query (e.g., "com.tinyspeck.slackdesktop"). |
app_name |
str
|
Human-readable application name for logging and component identification. |
version |
str
|
Expected version string to match. |
log_format |
LogFormat
|
Log format (currently only "cmtrace" supported). |
log_level |
LogLevel
|
Minimum log level (INFO, WARNING, ERROR, DEBUG). |
log_rotation_mb |
int
|
Maximum log file size in MB before rotation. |
exact_match |
bool
|
If True, version must match exactly. If False, minimum version comparison (installed >= expected). |
app_id |
str
|
Application ID (used for fallback identification). |
install_scope |
Literal['system', 'user']
|
Whether to query per-user ( |
Source code in napt/build/msix_scripts.py
MSIXRequirementsConfig
dataclass
Configuration for MSIX requirements script generation.
Attributes:
| Name | Type | Description |
|---|---|---|
identity_name |
str
|
Package identity name for AppX package query (e.g., "com.tinyspeck.slackdesktop"). |
app_name |
str
|
Human-readable application name for logging and component identification. |
version |
str
|
Target version string (requirement met if installed < this). |
log_format |
LogFormat
|
Log format (currently only "cmtrace" supported). |
log_level |
LogLevel
|
Minimum log level (INFO, WARNING, ERROR, DEBUG). |
log_rotation_mb |
int
|
Maximum log file size in MB before rotation. |
app_id |
str
|
Application ID (used for fallback identification). |
install_scope |
Literal['system', 'user']
|
Whether to query per-user ( |
Source code in napt/build/msix_scripts.py
generate_msix_detection_script
Generates PowerShell detection script for MSIX Win32 app.
Creates a PowerShell script that queries Get-AppxPackage for the
package identity and compares installed version against expected
version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
MSIXDetectionConfig
|
MSIX detection configuration. |
required |
output_path
|
Path
|
Path where the detection script will be saved. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the generated detection script. |
Raises:
| Type | Description |
|---|---|
OSError
|
If the script file cannot be written. |
Example
Generate script with default settings:
from pathlib import Path
from napt.build.msix_scripts import (
MSIXDetectionConfig,
generate_msix_detection_script,
)
config = MSIXDetectionConfig(
identity_name="com.tinyspeck.slackdesktop",
app_name="Slack",
version="4.49.81.0",
)
script_path = generate_msix_detection_script(
config,
Path("detection.ps1"),
)
Source code in napt/build/msix_scripts.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
generate_msix_requirements_script
Generates PowerShell requirements script for MSIX Win32 app.
Creates a PowerShell script that queries Get-AppxPackage for the
package identity and determines if an older version is installed.
Outputs "Required" if installed version < target, nothing otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
MSIXRequirementsConfig
|
MSIX requirements configuration. |
required |
output_path
|
Path
|
Path where the requirements script will be saved. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the generated requirements script. |
Raises:
| Type | Description |
|---|---|
OSError
|
If the script file cannot be written. |
Example
Generate script with default settings:
from pathlib import Path
from napt.build.msix_scripts import (
MSIXRequirementsConfig,
generate_msix_requirements_script,
)
config = MSIXRequirementsConfig(
identity_name="com.tinyspeck.slackdesktop",
app_name="Slack",
version="4.49.81.0",
)
script_path = generate_msix_requirements_script(
config,
Path("requirements.ps1"),
)
Source code in napt/build/msix_scripts.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |