-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppxPackage_Loopback_Exemption.ps1
More file actions
71 lines (61 loc) · 3.14 KB
/
AppxPackage_Loopback_Exemption.ps1
File metadata and controls
71 lines (61 loc) · 3.14 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#
# AppContainer Loopback Exemption Script v1.0
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# This is a Windows PowerShell (.ps1) script to exempt all AppContainers to
# perform network loopback (sending traffic to network IP 127.0.0.0).
#
# AppContainers/AppxPackages are the Microsoft legacy applications installed
# under AppContainer environment.
#
# By default, AppContainers are not allowed to perform loopback. This will
# prevent internet access against them, especially when a local proxy with
# loopback IP is applied.
#
# This script fixes the problem by scanning all AppxPackages installed in
# current computer by all users and adding them to the loopback exempted list.
#
Write-Host "The script is to add all AppContainers to the loopback exempted list."
Write-Host "NOTICE: This script requires administrator privilege to perform specific commands."
Write-Host "`nChecking the presense of administrator privilege..."
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
if ([int] (Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber -ge 6000) {
Write-Host "The script is not running with administrative privilege. The script will be elevated."
Write-Host "Please click `"Yes`" when UAC prompt appears."
$confirm = Read-Host -Prompt "`nProceed to execution [Y/N] ?"
if ($confirm -ieq "Y") {
Write-Host "Clearing loopback exempted AppContainer list..."
$arglist = "-Command `"CheckNetIsolation LoopbackExempt -c; (Get-AppxPackage -AllUsers).PackageFamilyName > '" + (Get-Location).Path + "\AppxPackages.txt'`""
Start-Process -FilePath PowerShell -Verb RunAs -ArgumentList "$arglist"
Pause
Write-Host "Adding AppContainers to loopback exempted list..."
$commandArr = @()
Get-Content "AppxPackages.txt" | ForEach-Object { $commandArr += "CheckNetIsolation LoopbackExempt -a -n='$_'" }
Remove-Item "AppxPackages.txt"
$commands = $commandArr -join ";"
$command = "-Command `"" + $commands + "`""
Start-Process -FilePath PowerShell -Verb RunAs -ArgumentList "$command"
Write-Host "`nDone."
}
else {
Write-Host "`nOperation aborted."
}
}
}
else {
Write-Host "The script is running with administrator privilege."
$confirm = Read-Host -Prompt "`nProceed to execution [Y/N] ?"
if ($confirm -ieq "Y") {
# Clear the list of loopback exempted AppContainers and Package Families.
Write-Host "Clearing loopback exempted AppContainer list..."
CheckNetIsolation LoopbackExempt -c
# Add all AppContainer or Package Family to the loopback exempted list.
Write-Host "Adding AppContainers to loopback exempted list..."
(Get-AppxPackage -AllUsers).PackageFamilyName | ForEach-Object { CheckNetIsolation LoopbackExempt -a -n="$_" }
Write-Host "`nDone."
}
else {
Write-Host "`nOperation aborted."
}
}
Pause