Created
November 25, 2021 15:09
-
-
Save KiruyaMomochi/1f887494347f8a1e353ff104296c140b to your computer and use it in GitHub Desktop.
Enable Loopback Exempt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-SingleAppPackage { | |
param ( | |
[Parameter(Mandatory = $true, | |
ValueFromPipeline = $true)] | |
[string] | |
$Name | |
) | |
$PackageNames = (Get-AppPackage).PackageFamilyName -match $Name | |
if ($PackageNames.Count -gt 1) { | |
$ErrorMessage = "The package family name is ambiguous, possible packages: " | |
$Packages = $PackageNames[0..2] -join ', ' | |
if ($PackageNames.Count -gt 3) { | |
$Packages += " and $($PackageNames.Count - 3) more." | |
} | |
$ErrorMessage += $Packages | |
Write-Error -Message $ErrorMessage -ErrorAction Stop | |
} | |
if ($PackageNames.Count -eq 0) { | |
Write-Error -Message "Package not found." -ErrorAction Stop | |
} | |
return $PackageNames | |
} | |
function Enable-LoopbackExempt { | |
param ( | |
[Parameter(Mandatory = $true, | |
ValueFromPipeline = $true, | |
ValueFromPipelineByPropertyName = $true, | |
ParameterSetName = "FamilyName", | |
Position=0)] | |
[string] | |
[ArgumentCompleter( | |
{ | |
param ( $commandName, | |
$parameterName, | |
$wordToComplete, | |
$commandAst, | |
$fakeBoundParameters ) | |
(Get-AppPackage).PackageFamilyName -match "$wordToComplete" | |
} | |
)] | |
$PackageFamilyName | |
) | |
try { | |
$null = Get-Command CheckNetIsolation.exe -ErrorAction Stop | |
} | |
catch { | |
Write-Error -Message "You don't have CheckNetIsolation.exe" -ErrorAction Stop | |
} | |
$PackageFamilyName = Get-SingleAppPackage $PackageFamilyName | |
Write-Debug "PackageFamilyName: $PackageFamilyName" | |
Write-Debug "CheckNetIsolation.exe LoopbackExempt -a -n=`"$PackageFamilyName`"" | |
CheckNetIsolation.exe LoopbackExempt -a -n="$PackageFamilyName" | |
} | |
function Clear-LoopbackExempt { | |
CheckNetIsolation.exe LoopbackExempt -c | |
} | |
Export-ModuleMember -Function Enable-LoopbackExempt, Clear-LoopbackExempt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment