So today I was tasked with creating a PowerShell script to sideload Windows Store apps for Windows 10. When I started looking at what I was being asked to do I realized that instead of creating a separate script for each of the apps that they want to load, it would be easier if I could create a generic script that would work for any .appxbundle package file.
First I created a variable for the script path:
$executingScriptDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
Then I used the “Get-Childitem” cmdlet with an “-include” parameter to choose the .appxbundle file type:
Get-Childitem $executingScriptDirectory -include *.AppxBundle -recurse
In order to account for the possibility that there would be more than one .appxbundle package in the folder I am running the script from, I piped the Get-Childitem to a foreach and then called on the “Add-AppxPackage” cmdlet:
Get-Childitem $executingScriptDirectory -include *.AppxBundle -recurse | foreach ($_) {Add-AppxPackage $_.fullname}
My final code looked like this:
## Set variable for directory where script and appx package reside $executingScriptDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent ## Run for every .appxbundle file found in the directory Get-Childitem $executingScriptDirectory -include *.AppxBundle -recurse | foreach ($_) { ## Install appx package Add-AppxPackage $_.fullname }
Of course, this doesn’t account for regular .appx files, nor does it work when your appx or appxbundle file requires a dependency. Since I didn’t have a need for those options I didn’t expand on my script to include them, but if you do, then at least this script might be a good jumping off point for you.
That’s all for now. Tune in next time for more random software deployment tips!