diff --git a/Perf Testing pesterv5.ps1 b/Perf Testing pesterv5.ps1 index b4561766..d7cc1135 100644 --- a/Perf Testing pesterv5.ps1 +++ b/Perf Testing pesterv5.ps1 @@ -12,11 +12,10 @@ ipmo ./dbachecks.psd1 -# +# $Checks = 'TraceFlagsExpected','TwoDigitYearCutoff','MaxDopInstance','ErrorLogCount','ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation' -$Checks = 'TraceFlagsExpected' -Compare-CheckRuns -Checks $checks + <# When there are default skips (some of the CIS checks) we need to set the configs and check @@ -58,14 +57,14 @@ Disable-DbaTraceFlag -SqlInstance $Sqlinstances -SqlCredential $cred -TraceFlag # If you get odd results - or you dont get any checks run -# run the import module and the Invoke Dbc Check with Verbose and that might show you New-Json messing +# run the import module and the Invoke Dbc Check with Verbose and that might show you New-Json messing # with your files or that you are looking in PSMOdulePath instead of Git Repo path (run Reset-dbcConfig to fix that) function Compare-CheckRuns { param($Checks) $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' +$Sqlinstances = 'localhost,14333', 'localhost,14334' #'localhost,7401', 'localhost,7402', 'localhost,7403' $originalCode = { Invoke-DbcCheck -SqlInstance $Sqlinstances -Check $Checks -SqlCredential $cred -legacy $true -Show None @@ -82,16 +81,16 @@ $originalCodeMessage = "With original Code it takes {0} MilliSeconds" -f $origin $savingMessage = " -Running with +Running with -{3} +{3} -Checks against 3 SQL Containers +Checks against $($Sqlinstances.Count) SQL Containers With original Code it takes {1} Seconds With New Code it takes {4} Seconds -New Code for these {5} checks +New Code for these {5} checks is saving {0} seconds from a run of {1} seconds New Code runs in {2} % of the time @@ -100,3 +99,7 @@ cls Write-PSFMessage -Message $savingMessage -Level Output } + + +$Checks = 'DbaOperator' +Compare-CheckRuns -Checks $checks \ No newline at end of file diff --git a/checks/Agentv5.Tests.ps1 b/checks/Agentv5.Tests.ps1 index 7b7043b3..7fee1339 100644 --- a/checks/Agentv5.Tests.ps1 +++ b/checks/Agentv5.Tests.ps1 @@ -6,14 +6,14 @@ BeforeDiscovery { # Gather the instances we know are not contactable [string[]]$NotContactable = (Get-PSFConfig -Module dbachecks -Name global.notcontactable).Value # Get all the tags in use in this run - $Tags = Get-CheckInformation -Check $Check -Group Instance -AllChecks $AllChecks -ExcludeCheck $ChecksToExclude + $Tags = Get-CheckInformation -Check $Check -Group Agent -AllChecks $AllChecks -ExcludeCheck $ChecksToExclude $InstancesToTest = @(Get-Instance).ForEach{ # just add it to the Not Contactable list if ($NotContactable -notcontains $psitem) { $Instance = $psitem try { - $InstanceSMO = Connect-DbaInstance -SqlInstance $Instance -ErrorAction SilentlyContinue -ErrorVariable errorvar + $InstanceSMO = Connect-DbaInstance -SqlInstance $Instance -ErrorAction SilentlyContinue -ErrorVariable errorvar } catch { $NotContactable += $Instance @@ -37,15 +37,40 @@ BeforeDiscovery { Describe "Database Mail XPs" -Tag DatabaseMailEnabled, CIS, security -ForEach $InstancesToTest { - $DatabaseMailEnabled = Get-DbcConfigValue policy.security.DatabaseMailEnabled $skip = Get-DbcConfigValue skip.agent.databasemailenabled Context "Testing Database Mail XPs on <_.Name>" { - It "Testing Database Mail XPs is set to $DatabaseMailEnabled on <_.Name>" -Skip:$skip { - $PSItem.Configuration.DatabaseMailEnabled | Should -Be $PSItem.ConfigValues.DatabaseMailEnabled -Because 'The Database Mail XPs setting should be set correctly' + It "Testing Database Mail XPs is set to <_.DatabaseMailEnabled> on <_.Name>" -Skip:$skip { + $PSItem.DatabaseMailEnabled | Should -Be $PSItem.ConfigValues.DatabaseMailEnabled -Because 'The Database Mail XPs setting should be set correctly' } } } +Describe "SQL Agent Account" -Tag AgentServiceAccount, ServiceAccount -ForEach $InstancesToTest { + #can't check agent on container - hmm does this actually work with instance need to check + #if (-not $IsLinux -and ($PSItem.HostPlatform -ne 'Linux')) { + $skipServiceState = Get-DbcConfigValue skip.agent.servicestate + $skipServiceStartMode = Get-DbcConfigValue skip.agent.servicestartmode + + Write-PSFMessage -Message "Agent = $($PSItem | Out-String)" -Level Verbose + + Context "Testing SQL Agent is running on <_.Name>" { + It "SQL Agent should be running for <_.InstanceName> on <_.Name>" -Skip:$skipServiceState { + $PSItem.Agent.State | Should -Be "Running" -Because 'The agent service is required to run SQL Agent jobs' + } + } + if ($PSItem.IsClustered) { + It "SQL Agent service should have a start mode of Manual for FailOver Clustered Instance <_.InstanceName> on <_.Name>" -Skip:$skipServiceStartMode { + $PSItem.Agent.StartMode | Should -Be "Manual" -Because 'Clustered Instances required that the Agent service is set to manual' + } + } + else { + It "SQL Agent service should have a start mode of Automatic for standalone instance <_.InstanceName> on <_.Name>" -Skip:$skipServiceStartMode { + $PSItem.Agent.StartMode | Should -Be "Automatic" -Because 'Otherwise the Agent Jobs wont run if the server is restarted' + } + } + #} +} + # Describe "SQL Agent Account" -Tags AgentServiceAccount, ServiceAccount, $filename { # if ($NotContactable -contains $psitem) { # Context "Testing SQL Agent is running on $psitem" { @@ -466,4 +491,7 @@ Describe "Database Mail XPs" -Tag DatabaseMailEnabled, CIS, security -ForEach $I # } # } # } -# } \ No newline at end of file +# } + + + diff --git a/checks/Databasev5.Tests.ps1 b/checks/Databasev5.Tests.ps1 index 3b91dd78..360ce48c 100644 --- a/checks/Databasev5.Tests.ps1 +++ b/checks/Databasev5.Tests.ps1 @@ -1,33 +1,6 @@ # So the v5 files need to be handled differently. -# Ww will start with a BeforeDiscovery which for the Database Checks will need to gather the Instances up front +# Ww will start with a BeforeDiscovery , $Filename which for the Database Checks will need to gather the Instances up front BeforeDiscovery { - <# - . $PSScriptRoot/../internal/assertions/Database.Assertions.ps1 - [array]$ExcludedDatabases = Get-DbcConfigValue command.invokedbccheck.excludedatabases - $ExcludedDatabases += $ExcludeDatabase - [string[]]$NotContactable = (Get-PSFConfig -Module dbachecks -Name global.notcontactable).Value - - $InstancesToTest = @(Get-Instance).ForEach{ - # just add it to the Not Contactable list - if ($NotContactable -notcontains $psitem) { - $Instance = $psitem - try { - $InstanceSMO = Connect-DbaInstance -SqlInstance $Instance -ErrorAction SilentlyContinue -ErrorVariable errorvar - } catch { - $NotContactable += $Instance - } - if ($NotContactable -notcontains $psitem) { - if ($null -eq $InstanceSMO.version) { - $NotContactable += $Instance - } else { - $InstanceSMO - } - } - } - } - Write-PSFMessage -Message "Instances = $InstancesToTest" -Level Significant - Set-PSFConfig -Module dbachecks -Name global.notcontactable -Value $NotContactable - #> # Gather the instances we know are not contactable [string[]]$NotContactable = (Get-PSFConfig -Module dbachecks -Name global.notcontactable).Value @@ -62,52 +35,55 @@ BeforeDiscovery { # Each Test will have a -ForEach for the Instances and the InstancesToTest object will have a # lot of information gathered up front to reduce trips and connections to the database + + <# -Describe "Database Collation" -Tag DatabaseCollation, High, Database -ForEach $InstancesToTest { - BeforeAll { - $Wrongcollation = Get-DbcConfigValue policy.database.wrongcollation - $exclude = "ReportingServer", "ReportingServerTempDB" - $exclude += $Wrongcollation - $exclude += $ExcludedDatabases +- copy in test +- add skip after describe + $skip = Get-DbcConfigValue skip.database.databasecollation + add to IT -Skip:$skip +#> - } - Context "Testing database collation on <_.Name>" { - It "Database <_.Database> collation <_.DatabaseCollation> should match server collation <_.ServerCollation> on <_.SqlInstance>" -ForEach @(Test-DbaDbCollation -SqlInstance $psitem -Database $Database -ExcludeDatabase $exclude) { - $psitem.ServerCollation | Should -Be $psitem.DatabaseCollation -Because "You will get collation conflict errors in tempdb" - } - if ($Wrongcollation) { - @(Test-DbaDbCollation -SqlInstance $psitem -Database $Wrongcollation ).ForEach{ - It "Database $($psitem.Database) collation ($($psitem.DatabaseCollation)) should not match server collation ($($psitem.ServerCollation)) on $($psitem.SqlInstance)" { - $psitem.ServerCollation | Should -Not -Be $psitem.DatabaseCollation -Because "You have defined the database to have another collation then the server. You will get collation conflict errors in tempdb" - } - } - } - } -} Describe "Suspect Page" -Tag SuspectPage, High , Database -ForEach $InstancesToTest { + $skip = Get-DbcConfigValue skip.database.suspectpage Context "Testing suspect pages on <_.Name>" { - It "Database <_.Name> should return 0 suspect pages on <_.Parent.Name>" -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database }else { $ExcludedDatabases -notcontains $PsItem.Name } } { - $results = Get-DbaSuspectPage -SqlInstance $psitem.Parent -Database $psitem.Name - @($results).Count | Should -Be 0 -Because "You do not want suspect pages - $results" + It "Database <_.Name> should return 0 suspect pages on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.suspectpageexclude -notcontains $PsItem.Name } } { + $psitem.SuspectPage | Should -Be 0 -Because "You do not want any suspect pages" } } } -#> -Describe "Valid Database Owner" -Tag ValidDatabaseOwner, Medium, Database -ForEach $InstancesToTest { - BeforeAll { - $ExcludedDatabases += Get-DbcConfigValue policy.validdbowner.excludedb +Describe "Database Collation" -Tag DatabaseCollation, High, Database -ForEach $InstancesToTest { + Context "Testing database collation on <_.Name>" { + $skip = Get-DbcConfigValue skip.database.databasecollation + It "Database <_.Name> collation <_.Collation> should match server collation <_.ServerCollation> on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.wrongcollation -notcontains $PsItem.Name } } { + $psitem.ServerCollation | Should -Be $psitem.Collation -Because "You will get collation conflict errors in tempdb" + } + + # wrong collation set + It "Database <_.Name> collation <_.Collation> should not match server collation <_.ServerCollation> on <_.SqlInstance>" -ForEach $psitem.Databases.Where{ $_.Name -in $psitem.ConfigValues.wrongcollation } { + $psitem.ServerCollation | Should -Not -Be $psitem.Collation -Because "You have defined the database to have another collation then the server. You will get collation conflict errors in tempdb" + } + } - #add skip but where - #$skip = Get-DbcConfigValue skip.instance.scanforstartupproceduresdisabled +} + +Describe "Valid Database Owner" -Tag ValidDatabaseOwner, Medium, Database -ForEach $InstancesToTest { + $skip = Get-DbcConfigValue skip.database.validdatabaseowner Context "Testing Database Owners on <_.Name>" { #TODO fix the it text - needs commas --> should be in this list ( sqladmin sa ) ) - It "Database <_.Name> - owner '<_.Owner>' should be in this list ( <_.ConfigValues.validdbownername> ) ) on <_.Parent.Name>" -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database }else { $ExcludedDatabases -notcontains $PsItem.Name } } { + It "Database <_.Name> - owner '<_.Owner>' should be in this list ( <_.ConfigValues.validdbownername> ) ) on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.validdbownerexclude -notcontains $PsItem.Name } } { $psitem.Owner | Should -BeIn $psitem.ConfigValues.validdbownername -Because "The account that is the database owner is not what was expected" } } } + + +#and can evey check have a skip policy.GROUP.UNIQUETAG - if it doesnt have one already and that will live on the line below the describe + + + diff --git a/internal/configurations/configuration.ps1 b/internal/configurations/configuration.ps1 index d2da0f7a..78a63fb6 100644 --- a/internal/configurations/configuration.ps1 +++ b/internal/configurations/configuration.ps1 @@ -152,7 +152,7 @@ Set-PSFConfig -Module dbachecks -Name policy.database.logfilesizepercentage -Val Set-PSFConfig -Module dbachecks -Name policy.database.logfilesizecomparison -Validation validation.logfilecomparisonvalidations -Value 'average' -Initialize -Description "How to compare data and log file size, options are maximum or average" Set-PSFConfig -Module dbachecks -Name policy.database.filebalancetolerance -Value 5 -Initialize -Description "Percentage for Tolerance for checking for balanced files in a filegroups" Set-PSFConfig -Module dbachecks -Name policy.database.filegrowthfreespacethreshold -Value 20 -Initialize -Description "Integer representing percentage of free space within a database file before warning" -Set-PSFConfig -Module dbachecks -Name policy.database.wrongcollation -Value @() -Initialize -Description "Databases that doesnt match server collation check" +Set-PSFConfig -Module dbachecks -Name policy.database.wrongcollation -Value @('ReportingServer', 'ReportingServerTempDB') -Initialize -Description "Databases that doesnt match server collation check" Set-PSFConfig -Module dbachecks -Name policy.database.maxdopexcludedb -Value @() -Initialize -Description "Database Names that we don't want to check for maxdop" Set-PSFConfig -Module dbachecks -Name policy.database.maxdop -Value 0 -Initialize -Description "The value for the database maxdop that we expect" Set-PSFConfig -Module dbachecks -Name policy.database.status.excludereadonly -Value @() -Initialize -Description "Database names that we expect to be readonly" @@ -246,6 +246,11 @@ Set-PSFConfig -Module dbachecks -Name skip.logfilecounttest -Validation bool -Va Set-PSFConfig -Module dbachecks -Name skip.diffbackuptest -Validation bool -Value $false -Initialize -Description "Skip the Differential backup test" Set-PSFConfig -Module dbachecks -Name skip.database.filegrowthdisabled -Validation bool -Value $true -Initialize -Description "Skip validation of datafiles which have growth value equal to zero." Set-PSFConfig -Module dbachecks -Name skip.database.logfilecounttest -Validation bool -Value $false -Initialize -Description "Skip the logfilecount test" +Set-PSFConfig -Module dbachecks -Name skip.database.validdatabaseowner -Validation bool -Value $false -Initialize -Description "Skip the valid database owner test" +Set-PSFConfig -Module dbachecks -Name skip.database.databasecollation -Validation bool -Value $false -Initialize -Description "Skip the database collation test" +Set-PSFConfig -Module dbachecks -Name skip.database.suspectpage -Validation bool -Value $false -Initialize -Description "Skip the suspect pages test" + + Set-PSFConfig -Module dbachecks -Name skip.logshiptesting -Validation bool -Value $false -Initialize -Description "Skip the logshipping test" Set-PSFConfig -Module dbachecks -Name skip.instance.modeldbgrowth -Validation bool -Value $false -Initialize -Description "Skip the model database growth settings test" Set-PSFConfig -Module dbachecks -Name skip.cluster.netclusterinterface -Validation bool -Value $false -Initialize -Description "Skip cluster private network interface checks" @@ -254,7 +259,11 @@ Set-PSFConfig -Module dbachecks -Name skip.hadr.listener.tcpport -Validation boo Set-PSFConfig -Module dbachecks -Name skip.hadr.replica.tcpport -Validation bool -Value $false -Initialize -Description "Skip the HADR Replica TCP port number (If port number is not standard across the entire AG architecture)" Set-PSFConfig -Module dbachecks -Name skip.hadr.listener.pingcheck -Validation bool -Value $false -Initialize -Description "Skip the HADR listener ping test (especially useful for Azure and AWS)" Set-PSFConfig -Module dbachecks -Name skip.instance.defaulttrace -Validation bool -Value $false -Initialize -Description "Skip the default trace check" -Set-PSFConfig -Module dbachecks -Name skip.agent.databasemailenabled -Validation bool -Value $false -Initialize -Description "Skip the long Database Mail Enabled agent check" +Set-PSFConfig -Module dbachecks -Name skip.agent.databasemailenabled -Validation bool -Value $false -Initialize -Description "Skip the Database Mail Enabled agent check" +Set-PSFConfig -Module dbachecks -Name skip.agent.servicestartmode -Validation bool -Value $false -Initialize -Description "Skip the Agent Service State check" +Set-PSFConfig -Module dbachecks -Name skip.agent.servicestate -Validation bool -Value $false -Initialize -Description "Skip the Agent Service Start Mode check" +Set-PSFConfig -Module dbachecks -Name skip.agent.operatorname -Validation bool -Value $false -Initialize -Description "Skip the Agent Operator Name check" +Set-PSFConfig -Module dbachecks -Name skip.agent.operatoremail -Validation bool -Value $false -Initialize -Description "Skip the Agent Operator Email check" Set-PSFConfig -Module dbachecks -Name skip.agent.longrunningjobs -Validation bool -Value $false -Initialize -Description "Skip the long running agent jobs check" Set-PSFConfig -Module dbachecks -Name skip.agent.lastjobruntime -Validation bool -Value $false -Initialize -Description "Skip the last agent job time check" Set-PSFConfig -Module dbachecks -Name skip.instance.dac -Validation bool -Value $false -Initialize -Description "Skip Dedicated Administrator Connection (DAC) check" @@ -332,7 +341,8 @@ Set-PSFConfig -Module dbachecks -Name command.invokedbccheck.excludedatabases -V Set-PSFConfig -Module dbachecks -Name testing.integration.instance -Value @("localhost") -Initialize -Description "Default SQL Server instances to be used by integration tests" # Suspect pages -Set-PSFConfig -Module dbachecks -Name policy.suspectpages.threshold -Value 90 -Initialize -Description "Default threshold (%) to check whether suspect_pages is nearing row limit of 1000" +Set-PSFConfig -Module dbachecks -Name policy.suspectpage.excludedb -Value 90 -Initialize -Description "Default threshold (%) to check whether suspect_pages is nearing row limit of 1000" +Set-PSFConfig -Module dbachecks -Name policy.suspectpage.threshold -Value 90 -Initialize -Description "Default threshold (%) to check whether suspect_pages is nearing row limit of 1000" # Server Set-PSFConfig -Module dbachecks -Name policy.server.cpuprioritisation -Value $true -Initialize -Description "Shall we skip the CPU Prioritisation check" diff --git a/internal/functions/Get-AllAgentInfo.ps1 b/internal/functions/Get-AllAgentInfo.ps1 index abefc1cc..3c82897b 100644 --- a/internal/functions/Get-AllAgentInfo.ps1 +++ b/internal/functions/Get-AllAgentInfo.ps1 @@ -7,6 +7,7 @@ function Get-AllAgentInfo { $Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Database], $false) $Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Login], $false) $Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Agent.Job], $false) + $Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Agent.Operator], $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) @@ -20,6 +21,9 @@ function Get-AllAgentInfo { $ServerInitFields.Add("VersionMajor") | Out-Null # so we can check versions $Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Server], $ServerInitFields) + # Job Server Initial fields + $OperatorInitFields = $Instance.GetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Agent.Operator]) + # Database Initial Fields $DatabaseInitFields = $Instance.GetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Database]) @@ -51,13 +55,47 @@ function Get-AllAgentInfo { 'DatabaseMailEnabled' { $configurations = $true - $ConfigValues | Add-Member -MemberType NoteProperty -Name 'databasemailenabled' -Value (Get-DbcConfigValue policy.security.databasemailenabled) + $ConfigValues | Add-Member -MemberType NoteProperty -Name 'DatabaseMailEnabled' -Value (Get-DbcConfigValue policy.security.databasemailenabled) } 'AgentServiceAccount' { - + if (($Instance.VersionMajor -ge 14) -or $IsLinux -or $Instance.HostPlatform -eq 'Linux') { + $Agent = @($Instance.Query("SELECT status_desc, startup_type_desc FROM sys.dm_server_services") | Where-Object servicename -like '*Agent*').ForEach{ + [PSCustomObject]@{ + State = $PSItem.status_desc + StartMode = $PSItem.startup_type_desc + } + } + } else { # Windows + $Agent = @(Get-DbaService -ComputerName $Instance.ComputerName -Type Agent) + } } 'DbaOperator' { - + $OperatorInitFields.Add("Name") | Out-Null # so we can check operators + $Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Agent.Operator], $OperatorInitFields) + $OperatorInitFields = $Instance.GetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Agent.Operator]) + + $ConfigValues | Add-Member -MemberType NoteProperty -Name 'DbaOperatorName' -Value (Get-DbcConfigValue agent.dbaoperatorname) + $ConfigValues | Add-Member -MemberType NoteProperty -Name 'DbaOperatorEmail' -Value (Get-DbcConfigValue agent.dbaoperatoremail) + + $Operator = $ConfigValues.DbaOperatorName.ForEach{ + [PSCustomObject]@{ + InstanceName = $Instance.Name + ExpectedOperatorName = $PSItem + ActualOperatorName = $Instance.JobServer.Operators.Name + ExpectedOperatorEmail = 'null' + ActualOperatorEmail = 'null' + } + } + + $Operator += $ConfigValues.DbaOperatorEmail.ForEach{ + [PSCustomObject]@{ + InstanceName = $Instance.Name + ExpectedOperatorName = 'null' + ActualOperatorName = 'null' + ExpectedOperatorEmail = $PSItem + ActualOperatorEmail = $Instance.JobServer.Operators.EmailAddress + } + } } 'FailsafeOperator' { @@ -97,7 +135,12 @@ function Get-AllAgentInfo { ComputerName = $Instance.ComputerName InstanceName = $Instance.DbaInstanceName Name = $Instance.Name - DatabaseMailEnabled = $Instance.Configuration.DatabaseMailEnabled.RunValue + ConfigValues = @($ConfigValues) + HostPlatform = $Instance.HostPlatform + IsClustered = $Instance.IsClustered + DatabaseMailEnabled = $Instance.Configuration.DatabaseMailEnabled.ConfigValue + Agent = @($Agent) + Operator = @($Operator) } return $testInstanceObject } \ No newline at end of file diff --git a/internal/functions/Get-AllDatabaseInfo.ps1 b/internal/functions/Get-AllDatabaseInfo.ps1 index 5adfe136..6a572d3c 100644 --- a/internal/functions/Get-AllDatabaseInfo.ps1 +++ b/internal/functions/Get-AllDatabaseInfo.ps1 @@ -52,7 +52,19 @@ function Get-AllDatabaseInfo { 'ValidDatabaseOwner' { $owner = $true $ConfigValues | Add-Member -MemberType NoteProperty -Name 'validdbownername' -Value (Get-DbcConfigValue policy.validdbowner.name) + $ConfigValues | Add-Member -MemberType NoteProperty -Name 'validdbownerexclude' -Value (Get-DbcConfigValue policy.validdbowner.excludedb) } + + 'DatabaseCollation' { + $collation = $true + $ConfigValues | Add-Member -MemberType NoteProperty -Name 'wrongcollation' -Value (Get-DbcConfigValue policy.database.wrongcollation) + } + + 'SuspectPage' { + $suspectPage = $true + $ConfigValues | Add-Member -MemberType NoteProperty -Name 'suspectpageexclude' -Value (Get-DbcConfigValue policy.suspectpage.excludedb) + } + Default { } } @@ -61,13 +73,19 @@ function Get-AllDatabaseInfo { ComputerName = $Instance.ComputerName InstanceName = $Instance.DbaInstanceName Name = $Instance.Name + ConfigValues = $ConfigValues # can we move this out? Databases = $Instance.Databases.Foreach{ [PSCustomObject]@{ Name = $psitem.Name - Owner = $psitem.owner - ConfigValues = $ConfigValues + SqlInstance = $Instance.Name + Owner = if ($owner) { $psitem.owner } + ServerCollation = if ($collation) { $Instance.collation } + Collation = if ($collation) { $psitem.collation } + SuspectPage = if ($suspectPage) { (Get-DbaSuspectPage -SqlInstance $Instance -Database $psitem.Name | Measure-Object).Count } + ConfigValues = $ConfigValues # can we move this out? } } } return $testInstanceObject -} \ No newline at end of file +} +