Create firewall rule even if path is not existing

Welcome Forums General PowerShell Q&A Create firewall rule even if path is not existing

  • This topic has 1 reply, 2 voices, and was last updated 1 month ago by
Viewing 1 reply thread
  • Author
    • #233608
      Topics: 2
      Replies: 0
      Points: 24
      Rank: Member


      I have here a script from Microsoft to create two rules in the Firewall, but after testing, teams application has to be installed, which are not the case for all our corporate devices. Is it possible to change this powershell ,and create the two rules, even if the path doesn’t exist?

      Thank you for your help

      $users = Get-ChildItem (Join-Path -Path $env:SystemDrive -ChildPath ‘Users’) -Exclude ‘Public’, ‘ADMINI~*’
      if ($null -ne $users) {
      foreach ($user in $users) {
      $progPath = Join-Path -Path $user.FullName -ChildPath “AppData\Local\Microsoft\Teams\Current\Teams.exe”
      if (Test-Path $progPath) {
      if (-not (Get-NetFirewallApplicationFilter -Program $progPath -ErrorAction SilentlyContinue)) {
      $ruleName = “Teams.exe for user $($user.Name)”
      “UDP”, “TCP” | ForEach-Object { New-NetFirewallRule -DisplayName $ruleName -Direction Inbound -Profile Any -Program $progPath -Action Allow -Protocol $_ }
      Clear-Variable ruleName
      Clear-Variable progPath

    • #233716
      Topics: 5
      Replies: 2373
      Points: 6,011
      Helping Hand
      Rank: Community MVP

      When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to you help making their work twice or more.


Viewing 1 reply thread
  • You must be logged in to reply to this topic.