From c2bc14ae5a23699510ea89d2f61b71759b656927 Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Thu, 30 Mar 2023 12:57:24 +0000 Subject: [PATCH] server name match should be checked #882 --- source/checks/Instancev5.Tests.ps1 | 11 +++++++++++ source/internal/configurations/configuration.ps1 | 1 + source/internal/functions/NewGet-AllInstanceInfo.ps1 | 11 +++++++++++ 3 files changed, 23 insertions(+) diff --git a/source/checks/Instancev5.Tests.ps1 b/source/checks/Instancev5.Tests.ps1 index b03b5c5f..5fc02f1e 100644 --- a/source/checks/Instancev5.Tests.ps1 +++ b/source/checks/Instancev5.Tests.ps1 @@ -399,6 +399,17 @@ Describe "Orphaned Files" -Tag OrphanedFile, Low, Instance -ForEach $InstancesTo } } } + +Describe "SQL and Windows names match" -Tag ServerNameMatch, Medium, Instance -ForEach $InstancesToTest { + $skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.instance.servernamematch' }).Value + Context "Testing SQL and Windows names match on <_.Name>" { + It "should have matching names on <_.Name>" -Skip:$skip { + $Psitem.ServerNameMatch.renamerequired | Should -BeFalse -Because "SQL and Windows names should match but configured name $($Psitem.ServerNameMatch.configuredServerName) does not match $($Psitem.ServerNameMatch.netName)" + } + } +} + + <# Describe "TempDB Configuration" -Tags TempDbConfiguration, Medium, Instance -ForEach $InstancesToTest { Context "Testing TempDB Configuration on $psitem" -Skip:(($__dbcconfig | Where-Object { $_.Name diff --git a/source/internal/configurations/configuration.ps1 b/source/internal/configurations/configuration.ps1 index 722abd4c..37cba2a9 100644 --- a/source/internal/configurations/configuration.ps1 +++ b/source/internal/configurations/configuration.ps1 @@ -284,6 +284,7 @@ Set-PSFConfig -Module dbachecks -Name skip.instance.networklatency -Validation b Set-PSFConfig -Module dbachecks -Name skip.instance.linkedserverconnection -Validation bool -Value $false -Initialize -Description "Skip the check for linked server connection" Set-PSFConfig -Module dbachecks -Name skip.instance.maxmemory -Validation bool -Value $false -Initialize -Description "Skip the check for max memory" Set-PSFConfig -Module dbachecks -Name skip.instance.orphanedfile -Validation bool -Value $false -Initialize -Description "Skip the check for orphaned file" +Set-PSFConfig -Module dbachecks -Name skip.instance.servernamematch -Validation bool -Value $false -Initialize -Description "Skip the check for server name match" diff --git a/source/internal/functions/NewGet-AllInstanceInfo.ps1 b/source/internal/functions/NewGet-AllInstanceInfo.ps1 index 15a5ccfe..062183dc 100644 --- a/source/internal/functions/NewGet-AllInstanceInfo.ps1 +++ b/source/internal/functions/NewGet-AllInstanceInfo.ps1 @@ -358,6 +358,12 @@ function NewGet-AllInstanceInfo { $FileCount = @(Find-DbaOrphanedFile -SqlInstance $Instance).Count } + ServerNameMatch { + $ServerNameMatchconfiguredServerName = $Instance.Query("SELECT @@servername AS ServerName").ServerName + $ServerNameMatchnetName = $Instance.NetName + $ServerNameMatchrenamerequired = $ServerNameMatchnetName -ne $ServerNameMatchconfiguredServerName + } + Default { } } @@ -451,6 +457,11 @@ function NewGet-AllInstanceInfo { OrphanedFile = [pscustomobject]@{ FileCount = $FileCount } + ServerNameMatch = [pscustomobject]@{ + configuredServerName = $ServerNameMatchconfiguredServerName + netName = $ServerNameMatchnetName + renamerequired = $ServerNameMatchrenamerequired + } # TempDbConfig = [PSCustomObject]@{ # TF118EnabledCurrent = $tempDBTest[0].CurrentSetting # TF118EnabledRecommended = $tempDBTest[0].Recommended