Skip to content

Commit

Permalink
so that we have orphanedfile checks #882
Browse files Browse the repository at this point in the history
  • Loading branch information
SQLDBAWithABeard committed Mar 30, 2023
1 parent dc7a1e8 commit 18319ae
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
20 changes: 10 additions & 10 deletions developing/Robs-Instance.ps1
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
$Checks = 'ErrorLogCount','TraceFlagsNotExpected','TraceFlagsExpected', 'XESessionRunningAllowed','XESessionRunning','XESessionRunningAllowed', 'XESessionExists','XESessionStopped','XpCmdShellDisabled','WhoIsActiveInstalled','CLREnabled','TwoDigitYearCutoff','MaxDopInstance','ErrorLogCount','ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation'
$Checks = 'ErrorLogCount', 'TraceFlagsNotExpected', 'TraceFlagsExpected', 'XESessionRunningAllowed', 'XESessionRunning', 'XESessionRunningAllowed', 'XESessionExists', 'XESessionStopped', 'XpCmdShellDisabled', 'WhoIsActiveInstalled', 'CLREnabled', 'TwoDigitYearCutoff', 'MaxDopInstance', 'ErrorLogCount', 'ModelDbGrowth', 'DefaultBackupCompression', 'SaExist', 'SaDisabled', 'SaRenamed', 'DefaultFilePath', 'AdHocDistributedQueriesEnabled', 'AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation'

$Checks = 'XESessionRunningAllowed','XESessionRunning','XESessionRunningAllowed','XESessionExists','XESessionStopped','XpCmdShellDisabled'
$Checks = 'TraceFlagsNotExpected','TraceFlagsExpected'
$Checks = 'XESessionRunningAllowed', 'XESessionRunning', 'XESessionRunningAllowed', 'XESessionExists', 'XESessionStopped', 'XpCmdShellDisabled'
$Checks = 'TraceFlagsNotExpected', 'TraceFlagsExpected'

Invoke-PerfAndValidateCheck -Checks $Checks
Invoke-PerfAndValidateCheck -Checks $Checks -PerfDetail

$containers = $SQLInstances = $dbachecks1, $dbachecks2, $dbachecks3 = 'dbachecks1', 'dbachecks2', 'dbachecks3'
$password = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "sqladmin", $password
$show = 'All'

$v4code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $true -Show $show -PassThru
# Run v5 checks
$v5code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $false -Show $show -PassThru -Verbose
$v5code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $false -Show $show -PassThru -Verbose

Set-DbcConfig -Name policy.xevent.requiredrunningsession -Value system_health
Set-DbcConfig -Name policy.xevent.requiredrunningsession -Value system_health ,AlwaysOn_health
Set-DbcConfig -Name policy.xevent.requiredrunningsession -Value system_health ,AlwaysOn_health,QuickSessionStandard
Set-DbcConfig -Name policy.xevent.requiredrunningsession -Value system_health
Set-DbcConfig -Name policy.xevent.requiredrunningsession -Value system_health , AlwaysOn_health
Set-DbcConfig -Name policy.xevent.requiredrunningsession -Value system_health , AlwaysOn_health, QuickSessionStandard

Set-DbcConfig -Name policy.xevent.validrunningsession -Value system_health ,AlwaysOn_health
Set-DbcConfig -Name policy.xevent.validrunningsession -Value system_health , AlwaysOn_health
Set-DbcConfig -Name policy.xevent.validrunningsession -Value AlwaysOn_health

$traci = Trace-Script -ScriptBlock {
$v5code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $false -Show $show -PassThru
$v5code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $false -Show $show -PassThru
}
8 changes: 8 additions & 0 deletions source/checks/Instancev5.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,14 @@ Describe "Max Memory" -Tag MaxMemory, High, Instance -ForEach $InstancesToTest {
}
}

Describe "Orphaned Files" -Tag OrphanedFile, Low, Instance -ForEach $InstancesToTest {
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.instance.orphanedfile' }).Value
Context "Testing Orphaned Files on <_.Name>" {
It "should not have orphaned files on <_.Name>" -Skip:$skip {
$Psitem.OrphanedFile.FileCount | Should -Be 0 -Because 'You dont want any orphaned files - Use Find-DbaOrphanedFile to locate them'
}
}
}
<#
Describe "TempDB Configuration" -Tags TempDbConfiguration, Medium, Instance -ForEach $InstancesToTest {
Context "Testing TempDB Configuration on $psitem" -Skip:(($__dbcconfig | Where-Object { $_.Name
Expand Down
1 change: 1 addition & 0 deletions source/internal/configurations/configuration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ Set-PSFConfig -Module dbachecks -Name skip.instance.BackupPathAccess -Validation
Set-PSFConfig -Module dbachecks -Name skip.instance.networklatency -Validation bool -Value $false -Initialize -Description "Skip the check for network latency"
Set-PSFConfig -Module dbachecks -Name skip.instance.linkedserverconnection -Validation bool -Value $false -Initialize -Description "Skip the check for linked server connection"
Set-PSFConfig -Module dbachecks -Name skip.instance.maxmemory -Validation bool -Value $false -Initialize -Description "Skip the check for max memory"
Set-PSFConfig -Module dbachecks -Name skip.instance.orphanedfile -Validation bool -Value $false -Initialize -Description "Skip the check for orphaned file"



Expand Down
7 changes: 7 additions & 0 deletions source/internal/functions/NewGet-AllInstanceInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ function NewGet-AllInstanceInfo {
}
}

OrphanedFile {
$FileCount = @(Find-DbaOrphanedFile -SqlInstance $Instance).Count
}

Default { }
}

Expand Down Expand Up @@ -444,6 +448,9 @@ function NewGet-AllInstanceInfo {
}
}
MaxMemory = $MaxMemory
OrphanedFile = [pscustomobject]@{
FileCount = $FileCount
}
# TempDbConfig = [PSCustomObject]@{
# TF118EnabledCurrent = $tempDBTest[0].CurrentSetting
# TF118EnabledRecommended = $tempDBTest[0].Recommended
Expand Down

0 comments on commit 18319ae

Please sign in to comment.