From 1a625b8014c9ee479b75266f789c34390121718a Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Tue, 28 Mar 2023 12:24:08 +0000 Subject: [PATCH] so that we can test linked server connections #882 --- source/checks/Instancev5.Tests.ps1 | 10 ++++++++ .../internal/configurations/configuration.ps1 | 1 + .../functions/NewGet-AllInstanceInfo.ps1 | 23 +++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/source/checks/Instancev5.Tests.ps1 b/source/checks/Instancev5.Tests.ps1 index abc6ff24..7ed8eb58 100644 --- a/source/checks/Instancev5.Tests.ps1 +++ b/source/checks/Instancev5.Tests.ps1 @@ -372,6 +372,16 @@ Describe "Network Latency" -Tag NetworkLatency, Connectivity, Medium, Instance - } } } + +Describe "Linked Servers" -Tags LinkedServerConnection, Connectivity, Medium, Instance -ForEach $InstancesToTest { + $skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.instance.linkedserverconnection' }).Value + Context "Testing Linked Server Connection on <_.Name>" { + It "should be able to connect to <_.LinkedServerName> for Linked Server <_.RemoteServer> on <_.InstanceName>" -Skip:$skip -ForEach @($Psitem.LinkedServerResults) { + $psitem.Connectivity | Should -BeTrue -Because "Linked server connection should be successful but the result was $($Psitem.Result)" + } + } +} + <# 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 1a5c1264..feca161d 100644 --- a/source/internal/configurations/configuration.ps1 +++ b/source/internal/configurations/configuration.ps1 @@ -281,6 +281,7 @@ Set-PSFConfig -Module dbachecks -Name skip.instance.errorlogentries -Validation Set-PSFConfig -Module dbachecks -Name skip.instance.tempdb -Validation bool -Value $false -Initialize -Description "Skip all the checks for the tempdb database" Set-PSFConfig -Module dbachecks -Name skip.instance.BackupPathAccess -Validation bool -Value $false -Initialize -Description "Skip the check for the backup path access check" Set-PSFConfig -Module dbachecks -Name skip.instance.networklatency -Validation bool -Value $false -Initialize -Description "Skip the check for network latency" +Set-PSFConfig -Module dbachecks -Name skip.instance.linkedserverconnection -Validation bool -Value $false -Initialize -Description "Skip the check for linked server connection" diff --git a/source/internal/functions/NewGet-AllInstanceInfo.ps1 b/source/internal/functions/NewGet-AllInstanceInfo.ps1 index 8853c9a5..103bf946 100644 --- a/source/internal/functions/NewGet-AllInstanceInfo.ps1 +++ b/source/internal/functions/NewGet-AllInstanceInfo.ps1 @@ -329,6 +329,10 @@ function NewGet-AllInstanceInfo { $Latency = (Test-DbaNetworkLatency -SqlInstance $Instance).NetworkOnlyTotal.TotalMilliseconds } + 'LinkedServerConnection' { + $LinkedServerResults = Test-DbaLinkedServerConnection -SqlInstance $Instance + } + Default { } } @@ -399,6 +403,25 @@ function NewGet-AllInstanceInfo { Latency = $Latency Threshold = $NetworkThreshold } + LinkedServerResults = if ($LinkedServerResults) { + $LinkedServerResults.ForEach{ + [pscustomobject]@{ + InstanceName = $Instance.Name + LinkedServerName = $PSItem.LinkedServerName + RemoteServer = $PSItem.RemoteServer + Connectivity = $PSItem.Connectivity + Result = $PSItem.Result + } + } + } else { + [pscustomobject]@{ + InstanceName = $Instance.Name + LinkedServerName = 'None found' + RemoteServer = 'None' + Connectivity = $true + Result = 'None' + } + } # TempDbConfig = [PSCustomObject]@{ # TF118EnabledCurrent = $tempDBTest[0].CurrentSetting # TF118EnabledRecommended = $tempDBTest[0].Recommended