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
    Participant
    .
Viewing 1 reply thread
  • Author
    Posts
    • #233608
      Participant
      Topics: 2
      Replies: 0
      Points: 24
      Rank: Member

      Hello

      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
      Participant
      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.

      https://social.technet.microsoft.com/Forums/en-US/a07fbde7-773d-4dea-9863-472a9f8f3050/create-firewall-rule-even-if-path-is-not-existing?forum=winserverpowershell

      Thanks

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