Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
103 lines (89 sloc) 3.21 KB
<#
.Synopsis
UWP app install wrapper
.DESCRIPTION
Installs (side-loads) an UWP app package
.EXAMPLE
Install-ProvisionedAppxPackage.ps1
.NOTES
Created: 2017-11-21
Version: 1.0
Author - Anton Romanyuk
Twitter: @admiraltolwyn
Blog : http://www.vacuumbreather.com
Disclaimer:
This script is provided 'AS IS' with no warranties, confers no rights and
is not supported by the author.
.LINK
http://www.vacuumbreather.com
.NOTES
#>
# 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
}
# https://stackoverflow.com/questions/8761888/capturing-standard-out-and-error-with-start-process
Function Execute-Command ($commandTitle, $commandPath, $commandArguments)
{
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = $commandPath
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.Arguments = $commandArguments
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$p.WaitForExit()
[pscustomobject]@{
commandTitle = $commandTitle
stdout = $p.StandardOutput.ReadToEnd()
stderr = $p.StandardError.ReadToEnd()
ExitCode = $p.ExitCode
}
}
# 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