Skip to content

Commit

Permalink
added defaultfilepath checks and tested #882
Browse files Browse the repository at this point in the history
  • Loading branch information
SQLDBAWithABeard committed Apr 26, 2022
1 parent 78858b9 commit 0400d39
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Validate v4 adn v5.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
#>
11 changes: 11 additions & 0 deletions checks/Instancev5.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
}
24 changes: 19 additions & 5 deletions internal/functions/NewGet-AllInstanceInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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

Expand Down Expand Up @@ -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 { }
}

Expand All @@ -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
}
}
Expand Down

0 comments on commit 0400d39

Please sign in to comment.