Skip to content

New-DbaFirewallRule - Fix binary path extraction and remove dead code#10294

Open
andreasjordan wants to merge 1 commit intodevelopmentfrom
claude/issue-9229-20260331-0620
Open

New-DbaFirewallRule - Fix binary path extraction and remove dead code#10294
andreasjordan wants to merge 1 commit intodevelopmentfrom
claude/issue-9229-20260331-0620

Conversation

@andreasjordan
Copy link
Copy Markdown
Collaborator

Fixes two bugs in the executable-based firewall rule implementation added for issue #9229.

Changes

  • Fix unsafe -replace for binary path extraction: PowerShell's -replace returns the original string unchanged when the pattern doesn't match. If BinaryPath didn't contain sqlservr.exe/sqlbrowser.exe, the original path value would silently be used as the firewall rule's Programpath. Changed to-match+$Matches[1]` which only sets the path when the regex actually matched.
  • Remove dead $programNeeded variable: Was set in two places but never read — actual logic relied on checking $rule.Config.Program directly.

Closes #9229

Generated with Claude Code

- Replace unsafe -replace regex (returns original string on no match, so a
  non-matching BinaryPath would silently produce a wrong Program path) with
  -match + $Matches[1] for both sqlservr.exe and sqlbrowser.exe detection
- Remove unused \$programNeeded variable (was set but never read)

(do New-DbaFirewallRule)

Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update New-DBAFirewallRule to target the executables instead of TCP/UDP port

1 participant