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

185 Views Asked by At

I need to come up with PowerShell code that puts a firewall rule in place, where this rule is tied to an executable that, in its turn, comes from an installed AppX package. The executable, thus, sits beneath C:\Program Files\WindowsApps.

Firewall rules can be tied to executables but is this the right approach in the case of an executable sitting beneath C:\Program Files\WindowsApps in the first place?

1

There are 1 best solutions below

1
danijeljw-RPC On

This can be done!

  1. Open an elevated powershell window
  2. Run the command Get-AppxPackage -AllUsers and find the name of the package you want (ie - Microsoft.WindowsCalculator_10.0.22000.0_x64__8wekyb3d8bbwe)
  3. Open the directory and find the executable file in there, and make a note of the full path
  4. Create a new firewall rule with powershell:
    a. New-NetFirewallRule -DisplayName "Allow Inbound Port 80 for Windows Calculator" -Direction Inbound -LocalPort 80 -Program "C:\Program Files\WindowsApps\Microsoft.WindowsCalculator_10.0.22000.0_x64__8wekyb3d8bbwe\calculator.exe" -Action Allow