From 434637d7f65572e65591dae512c6d7c25ec61500 Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Tue, 9 May 2023 09:07:24 +0100 Subject: [PATCH] so we can check for hideinstance #882 --- developing/Robs-Instance.ps1 | 1 + source/checks/Instancev5.Tests.ps1 | 10 ++++++++++ .../internal/functions/NewGet-AllInstanceInfo.ps1 | 13 +++++++++++++ 3 files changed, 24 insertions(+) diff --git a/developing/Robs-Instance.ps1 b/developing/Robs-Instance.ps1 index a80f148b..20fca50b 100644 --- a/developing/Robs-Instance.ps1 +++ b/developing/Robs-Instance.ps1 @@ -10,6 +10,7 @@ $Checks = 'LinkedServerConnection' $Checks = 'MaxMemory' $Checks = 'OrphanedFile' $Checks = 'MemoryDump' +$Checks = 'HideInstance' Invoke-PerfAndValidateCheck -Checks $Checks Invoke-PerfAndValidateCheck -Checks $Checks -PerfDetail diff --git a/source/checks/Instancev5.Tests.ps1 b/source/checks/Instancev5.Tests.ps1 index d9a6bb6c..8c7c8821 100644 --- a/source/checks/Instancev5.Tests.ps1 +++ b/source/checks/Instancev5.Tests.ps1 @@ -140,6 +140,16 @@ Describe "Error Log Count" -Tag ErrorLogCount, CIS, Low, Instance -ForEach $Inst } } +Describe "Hide Instance" -Tag HideInstance, Security, CIS, Medium, Instance -ForEach $InstancesToTest { + $skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.security.hideinstance' }).Value + Context "Checking the Hide an Instance of SQL Server Database Engine property on <_.Name>" { + It "The Hide an Instance of SQL Server Database Engine property on SQL Server instance <_.Name>" -Skip:$skip { + # We don't make this -BeTrue because the possible results are $true/$false/'Could not connect' + $psitem.HideInstance.Result | Should -Be $true -Because "We expected the hide instance property to be set to $true" + } + } +} + Describe "Instance Connection" -Tag InstanceConnection, Connectivity, High, Instance -ForEach $InstancesToTest { BeforeAll { $skipall = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.connection' }).Value diff --git a/source/internal/functions/NewGet-AllInstanceInfo.ps1 b/source/internal/functions/NewGet-AllInstanceInfo.ps1 index 5dddaaa0..db955997 100644 --- a/source/internal/functions/NewGet-AllInstanceInfo.ps1 +++ b/source/internal/functions/NewGet-AllInstanceInfo.ps1 @@ -388,6 +388,18 @@ function NewGet-AllInstanceInfo { } } + 'HideInstance' { + try { + $HideInstance = [pscustomobject] @{ + Result = (Get-DbaHideInstance -SqlInstance $InstanceSMO).HideInstance + } + } catch { + $HideInstance = [pscustomobject] @{ + Result = 'We Could not Connect to $Instance' + } + } + } + Default { } } @@ -487,6 +499,7 @@ function NewGet-AllInstanceInfo { renamerequired = $ServerNameMatchrenamerequired } MemoryDump = $Dump + HideInstance = $HideInstance # TempDbConfig = [PSCustomObject]@{ # TF118EnabledCurrent = $tempDBTest[0].CurrentSetting # TF118EnabledRecommended = $tempDBTest[0].Recommended