MSIX PowerShell Cmdlets

Written by Alex Marin · November 4th, 2021

#MSIX

MSIX uses the same PowerShell cmdlets available for AppX packages. But Microsoft added aliases for them not to create confusion between the AppX and MSIX packages.
Let’s go through some of them with a few examples.

To install an MSIX package from Powershell, run the command:

Add-AppPackage -path "C:\Caphyon\MyApp.msix"

The same command works for MSIX bundles as well:

Add-AppPackage -path “C:\Caphyon\MyBundle.msixbundle”

To remove an MSIX from PowerShell, you can use:

Remove-AppPackage -Package "Caphyon.MyApp_1.0.0.0_neutral__8wekyb3d8bbwe"

The removable package name is composed like Vendor.AppName_Version_Build_Hash, where Build can be neutral or X64. To remove the MSIX from all users, you can use:

Remove-AppPackage -Package "Caphyon.MyApp_1.0.0.0_neutral__8wekyb3d8bbwe" -AllUsers . 

ImportantTo remove it from all users you need to run the command as an administrator.

If you want to find additional information about a package, you can use

Get-AppPackage -name “Caphyon.MyApp”

This returns multiple fields, for example, the PackageFullName.You can use this to run the uninstall command mentioned above. If you want to find out all the MSIX/Appx packages installed, you can use Get-AppPackage, or you can use Get-AppPackage -User “Domain\Username” to get all the packages installed for a specific user.

By default, all the MSIX/Appx packages are installed in %ProgramFiles%\WindowsApps, but you can change that in a few simple steps. First, if you need, you can add a new Appx volume with Add-AppxVolume -Path "E:\WindowsApps".

ImportantIt’s necessary to specify \WindowsApps after the volume you choose.

After you added the new Volume, you can set it as default using Set-AppxDefaultVolume -Volume E:\. Now all your MSIX/Appx packages are installed by default in E:\WindowsApps.

With the new volumes in place, you can move installed MSIX packages by using:

Move-AppPackage -Package "Caphyon.MyApp_1.0.0.0_neutral__8wekyb3d8bbwe" -Volume E:\

To dismount a volume you can use: Dismount-AppxVolume -Volume E:\.

To remove a volume use: Remove-AppxVolume -Volume E:\.

ImportantIf you dismount a volume you cannot use the installed applications on that location

ImportantYou cannot remove a volume if any user has applications left on that location. You must first move/remove them.

To run an application inside the MSIX container you can use the Invoke-CommandInDesktopPackage cmdlet.

If you want to launch cmd.exe in your container you can use:

Invoke-CommandInDesktopPackage -PackageFamilyName "Caphyon.SampleMSIXPackage_r21n0w1rc5s2y" -appid "SampleMSIXPackage" -command "cmd.exe" -preventbreakaway

To view the merged registry hive, you can open up regedit.exe inside the MSIX with:

Invoke-CommandInDesktopPackage -PackageFamilyName "Caphyon.SampleMSIXPackage_r21n0w1rc5s2y" -appid "SampleMSIXPackage" -command "regedit.exe" -preventbreakaway

ImportantTo find out your MSIX AppID check out this blog

ImportantIf you want a faster and easier way to debug your applications, you can use the free Hover utility provided by Advanced Installer

PowerShell Cmdlets for MSIX Shared Containers

Starting with Windows 10 build 21354, Microsoft introduced support for MSIX Shared Containers.

With this update, there are new cmdlets included on the list, these are:

  • Add-AppSharedPackageContainer
  • Remove-AppSharedPackageContainer
  • Get-AppSharedPackageContainer
  • Reset-AppSharedPackageContainer

NoteBefore we go into the implementation of these cmdlets, it is important to note that Shared Package Containers are simple XML files. These XMLs require a unique Package Family Name for each package that belongs in that container.

A container example could look something like this:

<?xml version="1.0" encoding="utf-8"?>
<AppSharedPackageContainer Name="ContosoContainer">
<PackageFamily Name="Caphyon.WithoutImage_r21n0w1rc5s2y" />
<PackageFamily Name="Caphyon.TheImage_r21n0w1rc5s2y" />
</AppSharedPackageContainer>

To add a new shared container, the following cmdlet must be executed:

Add-AppSharedPackageContainer <path to XML>
Add shared container

To remove a shared container, you must execute the following cmdlet:

Remove-AppSharedPackageContainer -Name <name> 

If we have a look at the example XML file above, the Name of the shared container would be ContosoContainter.

To get information about the shared package container, i.e. what packages are inside the shared package container -- we can use the following cmdlet:

To reset a container, use the Reset cmdlet :

Reset-AppSharedPackageContainer -Name <name>

NoteThe reset cmdlet destroys all the application data of the container, including the virtual files and registry keys.

Get shared container
Get-AppSharedPackageContainer -Name <name>

For more cmdlets, check this link.

Video Tutorial - How to run scripts inside an MSIX package

Subscribe to Our Newsletter

Sign up for free and be the first to receive the latest news, videos, exclusive How-Tos, and guides from Advanced Installer.

Comments: