-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUWP-allusers-install-prompts.ps1
41 lines (36 loc) · 1.57 KB
/
UWP-allusers-install-prompts.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Check if the script is running with admin rights
function Test-Admin {
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($identity)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
# If not running as admin, try to restart as admin
if (-not (Test-Admin)) {
try {
Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
exit
} catch {
Write-Error "Failed to run as administrator. Please run this script with elevated privileges."
exit
}
}
# Get the directory of the script
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
# Find all MSIX, APPX, MSIXBUNDLE, and APPXBUNDLE files
$packages = Get-ChildItem -Path $scriptDir -Include *.msix, *.appx, *.msixbundle, *.appxbundle -Recurse
# Install each package with user confirmation
foreach ($package in $packages) {
$userResponse = Read-Host "Do you want to install $($package.Name)? (Y/N)"
if ($userResponse -eq 'Y' -or $userResponse -eq 'y') {
try {
Add-AppxProvisionedPackage -PackagePath $package.FullName -Online -SkipLicense
Write-Host "$($package.Name) installed successfully."
} catch {
Write-Error "Failed to install $($package.Name): $_"
}
} else {
Write-Host "Skipping installation of $($package.Name)."
}
}
# Keep the script open after completion
Read-Host "Press Enter to exit..."