PowerShell code to tie a firewall rule to a WindowsApps executable on Windows 10

  • 1 year ago
Comment

1 / 1

To tie a firewall rule to a WindowsApps executable on Windows 10 using PowerShell, you can use the New-NetFirewallRule cmdlet. Here is an example PowerShell code:

powershell
# Define the rule name and description
$RuleName = "AllowWindowsApps"
$RuleDescription = "Allow WindowsApps executable to communicate through the firewall"

# Define the WindowsApps executable path and arguments
$ExecutablePath = "C:\Windows\System32\LaunchWinApp.exe"
$ExecutableArguments = "-ServerName Microsoft.SkypeApp_kzf8qxf38zg5c!App"

# Create the firewall rule
New-NetFirewallRule -DisplayName $RuleName `
-Description $RuleDescription `
-Direction Inbound `
-Program $ExecutablePath `
-Argument $ExecutableArguments `
-Action Allow `
-Profile Any `
-Enabled True `

In this example, the New-NetFirewallRule cmdlet is used to create a new firewall rule that allows the WindowsApps executable to communicate through the firewall. The -DisplayName, -Description, and -Direction parameters are used to specify the name, description, and direction of the rule. The -Program and -Argument parameters are used to specify the path to the WindowsApps executable and its arguments. The -Action, -Profile, and -Enabled parameters are used to specify the action, profile, and enable status of the rule.

Note that you may need to modify the $ExecutablePath and $ExecutableArguments variables to match the WindowsApps executable you want to allow through the firewall. You can use the Get-AppxPackage cmdlet to list all the installed WindowsApps and their executable paths.