Skip to content

Commit 6147b5e

Browse files
New-DbaFirewallRule - Stop blaming a disabled DAC for a cycled ERRORLOG (#10528)
1 parent c118ae2 commit 6147b5e

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

public/New-DbaFirewallRule.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,10 @@ function New-DbaFirewallRule {
428428
}
429429

430430
if (-not $dacMessage) {
431-
Write-Message -Level Warning -Message "No information about the dedicated admin connection (DAC) found in ERRORLOG, cannot create firewall rule for DAC. Use 'Set-DbaSpConfigure -SqlInstance '$instance' -Name RemoteDacConnectionsEnabled -Value 1' to enable remote DAC and try again."
431+
# SQL Server writes this message when the instance starts, and we only read the
432+
# current ERRORLOG. A log that was cycled since the last start therefore looks
433+
# exactly like a disabled DAC, so we must not claim the DAC is disabled here.
434+
Write-Message -Level Warning -Message "No information about the dedicated admin connection (DAC) found in the current ERRORLOG, cannot create firewall rule for DAC. That message is only written when the instance starts, so it is missing if the ERRORLOG was cycled since then. If remote DAC is disabled on $instance, enable it with Set-DbaSpConfigure -Name RemoteDacConnectionsEnabled -Value 1 and restart the instance."
432435
} elseif ($dacMessage -match 'locally') {
433436
Write-Message -Level Verbose -Message "Dedicated admin connection is only listening locally, so no firewall rule is needed."
434437
} else {

tests/New-DbaFirewallRule.Tests.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ Describe $CommandName -Tag IntegrationTests {
151151
$null = Remove-DbaFirewallRule -SqlInstance $TestConfig.InstanceSingle
152152

153153
# Create firewall rules with default RuleType (Program)
154-
$resultsNew = New-DbaFirewallRule -SqlInstance $TestConfig.InstanceSingle
154+
# The rule for the DAC can only be created when the instance wrote the DAC port to the
155+
# current ERRORLOG, which it only does when it starts. On an instance whose ERRORLOG was
156+
# cycled since then the command warns instead, so the warning is silenced here. It says
157+
# nothing about the command and a test run must not print warnings.
158+
$resultsNew = New-DbaFirewallRule -SqlInstance $TestConfig.InstanceSingle -WarningAction SilentlyContinue
155159
$resultsGet = Get-DbaFirewallRule -SqlInstance $TestConfig.InstanceSingle
156160
$resultsRemoveBrowser = $resultsGet | Where-Object Type -eq "Browser" | Remove-DbaFirewallRule
157161
$resultsRemove = Remove-DbaFirewallRule -SqlInstance $TestConfig.InstanceSingle -Type AllInstance
@@ -228,7 +232,8 @@ Describe $CommandName -Tag IntegrationTests {
228232
$null = Remove-DbaFirewallRule -SqlInstance $TestConfig.InstanceSingle
229233

230234
# Create firewall rules with RuleType Port
231-
$resultsNewPort = New-DbaFirewallRule -SqlInstance $TestConfig.InstanceSingle -RuleType Port
235+
# Same as above: without the DAC port in the current ERRORLOG the command warns.
236+
$resultsNewPort = New-DbaFirewallRule -SqlInstance $TestConfig.InstanceSingle -RuleType Port -WarningAction SilentlyContinue
232237
$resultsGetPort = Get-DbaFirewallRule -SqlInstance $TestConfig.InstanceSingle
233238
$resultsRemovePort = Remove-DbaFirewallRule -SqlInstance $TestConfig.InstanceSingle -Type AllInstance
234239

0 commit comments

Comments
 (0)