As I mentioned in my previous blog post, I am not a fan of reinventing the wheel. From Michael Niehaus' Ignite presentations and blog ramblings, I knew that MDT automatically creates the needed DISM command line to provision the app, so I opened the ZTIApplications.wsf file and started poking around. After locating the long DISM command line I quickly put together a PowerShell script that basically mimics MDT's behavior in front of my audience. No pressure, eh? Below (and on GitHub) is the end result.
How does it work:
In the simplest of terms, all you need are the source files in the right folder structure and the PowerShell wrapper I put together.
To download the necessary source files, you need to use Microsoft Store for Business (previously known as Windows Store for Business). It has been around for quite a while (two years almost to the day in fact). It's a layer that sits on top of the consumer Microsoft Store. Go to the main entry page located at businessstore.microsoft.com. You can do two things there: you can sign-in, if you have used the Store before, or start the sign-up process. Once you are logged in, browse to your inventory.
Select an application that you have acquired for offline use and download all components.
Unfortunately, there is no "Download all", so the process is a little bit messy. Basically, you need the Appx bundle, which is the main application package...
... the unencoded license XML file...
... and the required frameworks.
Once you downloaded all the pieces, you need to put them in the right folder structure, similarly to an application created in Visual Studio. For instance, with the Microsoft Wireless Display Adapter app you will end up with the following folder structure:
- Root folder
- Install-ProvisionedAppxPackage.ps1
- AppxBundle
- Microsoft.SurfaceWirelessDisplayAdapter_3.0.124.0_neutral_~_8wekyb3d8bbwe.AppxBundle
- Microsoft.SurfaceWirelessDisplayAdapter_8wekyb3d8bbwe.xml
- Dependencies
- x64
- Microsoft.NET.Native.Runtime.1.1_1.1.23406.0_x64__8wekyb3d8bbwe.Appx
- Microsoft.VCLibs.140.00_14.0.25426.0_x64__8wekyb3d8bbwe.Appx
- x86
- Microsoft.NET.Native.Runtime.1.1_1.1.23406.0_x86__8wekyb3d8bbwe.Appx
- Microsoft.VCLibs.140.00_14.0.25426.0_x86__8wekyb3d8bbwe.Appx
- x64
- Dependencies
- AppxBundle
- Install-ProvisionedAppxPackage.ps1
The wrapper will locate the Appx bundle, unencoded license file and dependencies, set the policy to enable sideloading, build the necessary DISM command depending on the detected pieces to provision the application for you, run the DISM command and return the DISM exit code. You can run the script on a client machine either manually or by using your management tool. Ideally, the app will show up in the start menu. By default, the log file will be written to C:\temp\Log - you can adjust the path directly in the script.
So to summarize: download all the pieces, put them in the right folder structure, add the wrapper and run it. It is as simple as that.
Note: If you are not going to deploy private line-of-business apps and stick with the Microsoft Store for Business and Microsoft Store for Education applications which come with a license file, then you may want to remove the sideloading policy from the wrapper because it is not needed.
# Determine where to do the logging $logPath = "C:\temp\Logs" $logFile = "$logPath\$($myInvocation.MyCommand).log" $ScriptName = $MyInvocation.MyCommand # Check log path If (!(Test-Path $logPath)) { Write-Output "Log path not found..." New-Item -Path $logPath -ItemType Directory -Force } # Create Logfile Write-Output "$ScriptName - Create Logfile" > $logFile Function Logit($TextBlock1){ $TimeDate = Get-Date $OutPut = "$ScriptName - $TextBlock1 - $TimeDate" Write-Output $OutPut >> $logFile } # Start main code here . Logit "Make sure policy is set." Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\Appx" -Name "AllowAllTrustedApps" -Value "1" -Force | Out-Null . Logit "Build the base command line" # Determine where to check $AppxBundlePath = $PSScriptRoot + '\AppxBundle' $AppxBundle = (Get-ChildItem -Path $AppxBundlePath) | where-object {$_.FullName -like "*.AppxBundle"} $LicensePath = (Get-ChildItem -Path $AppxBundlePath) | where-object {$_.FullName -like "*.xml"} $DependenciesPath = $AppxBundlePath + "\Dependencies" $DependenciesList = (Get-ChildItem -Path $DependenciesPath -Recurse) | where-object {$_.FullName -like "*.appx"} $Dependencies = "" . Logit "Adding dependencies..." ForEach ($tmp in $DependenciesList) { $Dependencies += " /DependencyPackagePath:" + $tmp.FullName } # Add license If (!$LicensePath) { . Logit "No license file found..." $License = " /SkipLicense" } Else { . Logit "License file found..." $License = " /LicensePath:" + $LicensePath.FullName } # build command line $BuildAppxCommand = "/Online /Add-ProvisionedAppxPackage /PackagePath:" + $AppxBundle.FullName + $License + " /NoRestart" + $Dependencies # Launch Command and get return code . Logit "Installing application $($AppxBundle.Name)" . Logit "Command line $BuildAppxCommand" $DISM = Execute-Command -commandTitle "Install AppxProvisionedPackage" -commandPath DISM.exe -commandArguments $BuildAppxCommand $ExitCode = $DISM.ExitCode . Logit "Exit code from command $ExitCode" Exit $ExitCode