From 33011d215c64ed0d3a56f3077023ddf59700c377 Mon Sep 17 00:00:00 2001 From: jpomfret Date: Tue, 7 Mar 2023 20:06:37 +0000 Subject: [PATCH] add latestbuild check --- source/checks/Instancev5.Tests.ps1 | 9 +++++++++ source/internal/functions/NewGet-AllInstanceInfo.ps1 | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/source/checks/Instancev5.Tests.ps1 b/source/checks/Instancev5.Tests.ps1 index 3ebfb361..71f04813 100644 --- a/source/checks/Instancev5.Tests.ps1 +++ b/source/checks/Instancev5.Tests.ps1 @@ -346,6 +346,15 @@ Describe "Error Log Entries" -Tag ErrorLog, Medium, Instance -ForEach $Instances } } +Describe "Latest Build" -Tag LatestBuild, Security, CIS, Medium, Instance -ForEach $InstancesToTest { + $skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.instance.latestbuild' }).Value + Context "Testing Latest Build on <_.Name>" { + It "The Latest Build of SQL should be installed on <_.Name>" -Skip:$skip { + $psitem.LatestBuild.Compliant | Should -BeTrue -Because "being patched to the latest version is important" + } + } +} + <# 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/functions/NewGet-AllInstanceInfo.ps1 b/source/internal/functions/NewGet-AllInstanceInfo.ps1 index e17d563a..1a6b08ed 100644 --- a/source/internal/functions/NewGet-AllInstanceInfo.ps1 +++ b/source/internal/functions/NewGet-AllInstanceInfo.ps1 @@ -270,6 +270,9 @@ function NewGet-AllInstanceInfo { # It is not enough to check the CreateDate on the log, you must check the LogDate on every error record as well. $ErrorLogCount = (Get-ErrorLogEntry | Where-Object { $psitem.LogDate -gt (Get-Date).AddDays( - $LogWindow) }).Count } + 'LatestBuild' { + $LatestBuild = Test-DbaBuild -SqlInstance $Instance -Latest + } 'TempDbConfiguration' { $TempDBTest = Test-DbaTempDbConfig -SqlInstance $Instance } @@ -373,6 +376,9 @@ function NewGet-AllInstanceInfo { logWindow = $logWindow } InstanceConnection = $InstanceConnection + LatestBuild = [PSCustomObject]@{ + Compliant = $LatestBuild.Compliant + } # TempDbConfig = [PSCustomObject]@{ # TF118EnabledCurrent = $tempDBTest[0].CurrentSetting # TF118EnabledRecommended = $tempDBTest[0].Recommended