Install MSIX Package
Overview
This script will attempt to install an MSIX/APPX package on a system if not already installed.
If this script is being used with a Group Policy startup script and UNC path, make sure that the computer objects which the Group Policy targets has access to the MSIX/APPX package file as well.
Usage
Download and run locally
- Download the script:
Invoke-WebRequest -Uri https://techdocsoffline.com/powershell-snippets/Install-MSIXPackage.ps1 -OutFile Install-MSIXPackage.ps1
- Run the script with administrative privileges
Script Details
# =============================================================================# Script Name: Install MSIX Package# Version: 1.0.0# =============================================================================## DESCRIPTION:# Installs an MSIX/APPX package on a system if not already installed## PARAMETERS (required):# -PackageName : The partial or full package name used to verify installation status# -PackagePath : The local or remote UNC path of the source package to install## SOURCE:# https://techdocsoffline.com/powershell-snippets/install-msix-package/## DISCLAIMER:# This script is provided "AS IS" without warranties of any kind.# Always review scripts from the internet before executing them.## =============================================================================
param ( [Parameter(Mandatory = $true)] [string]$PackageName,
[Parameter(Mandatory = $true)] [string]$PackagePath)
# Check if the script is running with administrative privilegesif (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) { Write-Host "This script must be run as an administrator." -ForegroundColor Red exit}
# Check for matching provisioned packages$matchingPackages = Get-AppxProvisionedPackage -Online | Where-Object { $_.PackageName -like "*$PackageName*"}
if ($matchingPackages.Count -ge 1) { Write-Host "Exiting! Package count is greater than or equal to 1, this could indicate the package is already provisioned." Write-Host "Matching Packages:" $matchingPackages return}
# Check if the package source existsif (-not (Test-Path -Path $PackagePath)) { Write-Host "Exiting! Package source does not exist at $PackagePath" return}
Write-Host "Installing package from $PackagePath..."
# Install the packageAdd-AppxProvisionedPackage -Online -PackagePath $PackagePath -SkipLicense
Write-Host "Installation complete."
Parameters
Named Parameter | Description | Required | Example |
---|---|---|---|
PackageName | The partial or full package name to verify successful installation | Yes | com.owllabs.meetingowl.windows_4.7.1.143_x64__cb17j8khw3v66 |
PackagePath | The full local or remote UNC path of the package to install | Yes | \\Server.Example.tld\Software\meeting_owl_desktop_4.7.1.143.msix |
Examples
# Run the script.\Install-MSIXPackage.ps1 -PackageName com.owllabs.meetingowl.windows_4.7.1.143_x64__cb17j8khw3v66 -PackagePath \\Server.Example.tld\Software\meeting_owl_desktop_4.7.1.143.msix
Installing package from \\Server.Example.tld\Software\meeting_owl_desktop_4.7.1.143.msix...
Path :Online : TrueRestartNeeded : False
Installation complete.