diff --git a/Validate v4 adn v5.ps1 b/Validate v4 adn v5.ps1 index f45ebe8b..5a41d504 100644 --- a/Validate v4 adn v5.ps1 +++ b/Validate v4 adn v5.ps1 @@ -14,8 +14,8 @@ ipmo ./dbachecks.psd1 # -$Checks = 'AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation' -$Checks = 'AdHocDistributedQueriesEnabled' +$Checks = 'DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation' +$Checks = 'DefaultFilePath' Compare-v4andv5Results -Checks $Checks # Load the function below and then you can keep running the checks defined above in v4 and v5 and compare the performance @@ -134,6 +134,6 @@ For v5 we ran $password = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force $cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "sqladmin", $password $Sqlinstances = 'localhost,7401', 'localhost,7402', 'localhost,7403' -Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $false -PassThru -show None +Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $false Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $true #> \ No newline at end of file diff --git a/checks/Instancev5.Tests.ps1 b/checks/Instancev5.Tests.ps1 index 1611a731..04ca1b18 100644 --- a/checks/Instancev5.Tests.ps1 +++ b/checks/Instancev5.Tests.ps1 @@ -120,3 +120,14 @@ Describe "Ad Hoc Distributed Queries" -Tag AdHocDistributedQueriesEnabled, secur } } } +Describe "Default File Path" -Tag DefaultFilePath, Instance -ForEach $InstancesToTest { + $skip = Get-DbcConfigValue skip.instance.DefaultFilePath + Context "Checking Default Data File Path on <_.Name>" { + It "Default Data File Path should not be on the C Drive on <_.Name>" -Skip:$skip { + $PSItem.Settings.DefaultFile.substring(0, 1) | Should -Not -Be "C" -Because 'Default Data file path should not be your C:\ drive' + } + It "Default Log File Path should not be on the C Drive on <_.Name>" -Skip:$skip { + $PSItem.Settings.DefaultLog.substring(0, 1) | Should -Not -Be "C" -Because 'Default Log file path should not be your C:\ drive' + } + } +} diff --git a/internal/functions/NewGet-AllInstanceInfo.ps1 b/internal/functions/NewGet-AllInstanceInfo.ps1 index 60e8307f..9eccf540 100644 --- a/internal/functions/NewGet-AllInstanceInfo.ps1 +++ b/internal/functions/NewGet-AllInstanceInfo.ps1 @@ -8,6 +8,9 @@ function NewGet-AllInstanceInfo { $Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Login], $false) $Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Agent.Job], $false) $Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.StoredProcedure], $false) + $Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Information], $false) + $Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Settings], $false) + # Server Initial fields $ServerInitFields = $Instance.GetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Server]) @@ -18,6 +21,11 @@ function NewGet-AllInstanceInfo { $StoredProcedureInitFields = $Instance.GetDefaultInitFields([Microsoft.SqlServer.Management.Smo.StoredProcedure]) $StoredProcedureInitFields.Add("Startup") | Out-Null # So we can check SPs start up for the CIS checks + # Information Initial Fields + + # Settings Initial Fields + $SettingsInitFields = $Instance.GetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Settings]) + # Configuration cannot have default init fields :-) $configurations = $false @@ -64,7 +72,12 @@ function NewGet-AllInstanceInfo { $configurations = $true $ConfigValues | Add-Member -MemberType NoteProperty -Name 'AdHocDistributedQueriesEnabled' -Value (Get-DbcConfigValue policy.security.AdHocDistributedQueriesEnabled) } - + 'DefaultFilePath' { + $SettingsInitFields.Add("DefaultFile") | Out-Null # so we can check file paths + $SettingsInitFields.Add("DefaultLog") | Out-Null # so we can check file paths + $Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Settings], $SettingsInitFields) + } + Default { } } @@ -78,11 +91,12 @@ function NewGet-AllInstanceInfo { Name = $Instance.Name ConfigValues = $ConfigValues VersionMajor = $Instance.VersionMajor - Configuration = if ($configurations) { $Instance.Configuration }else { $null } + Configuration = if ($configurations) { $Instance.Configuration } else { $null } + Settings = $Instance.Settings } - if($ScanForStartupProceduresDisabled){ - $StartUpSPs = $Instance.Databases['master'].StoredProcedures.Where{$_. Name -ne 'sp_MSrepl_startup' -and $_.StartUp -eq $true}.count - if ($StartUpSPs -eq 0) { + if ($ScanForStartupProceduresDisabled) { + $StartUpSPs = $Instance.Databases['master'].StoredProcedures.Where{ $_. Name -ne 'sp_MSrepl_startup' -and $_.StartUp -eq $true }.count + if ($StartUpSPs -eq 0) { $testInstanceObject.Configuration.ScanForStartupProcedures.ConfigValue = 0 } }