Skip to content
2 changes: 1 addition & 1 deletion developing/settingupfor2022.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Get-DbaLogin -SqlInstance $sql1,$sql2,$sql3 | ft
Get-DbaDatabase -SqlInstance $sql1,$sql2,$sql3 | ft
Get-DbaAgentJob -SqlInstance $sql1,$sql2,$sql3 | ft
Get-DbaDbCertificate -SqlInstance $sql1,$sql2,$sql3 | ft

docker run -p 52000:1433 -v sqlserver:/var/opt/sqlserver -d dbatools/sqlinstance --name mssql1
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=dbatools.IO" -p 52002:1433 --name mssql3 --hostname mssql3 -v sqlserver:/var/opt/sqlserver -d mcr.microsoft.com/mssql/server:2022-latest

Expand Down
2 changes: 1 addition & 1 deletion source/checks/Agent.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$filename = $MyInvocation.MyCommand.Name.Replace('.Tests.ps1', '')
. $PSScriptRoot/../internal/assertions/Agent.Assertions.ps1
. (Convert-Path -Path $PSScriptRoot/../internal/assertions/Agent.Assertions.ps1)
[string[]]$NotContactable = (Get-PSFConfig -Module dbachecks -Name global.notcontactable).Value

Set-PSFConfig -Module dbachecks -Name global.notcontactable -Value $NotContactable
Expand Down
2 changes: 1 addition & 1 deletion source/checks/Database.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$filename = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
. $PSScriptRoot/../internal/assertions/Database.Assertions.ps1
. (Convert-Path -Path $PSScriptRoot/../internal/assertions/Database.Assertions.ps1)


[array]$ExcludedDatabases = Get-DbcConfigValue command.invokedbccheck.excludedatabases
Expand Down
2 changes: 1 addition & 1 deletion source/checks/Instance.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$filename = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
. $PSScriptRoot/../internal/assertions/Instance.Assertions.ps1
. (Convert-Path -Path $PSScriptRoot/../internal/assertions/Instance.Assertions.ps1)

# Check out the comments at the top of Instance.Assertions for guidance on adding checks

Expand Down
28 changes: 13 additions & 15 deletions source/checks/Server.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
$filename = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
. $PSScriptRoot/../internal/assertions/Server.Assertions.ps1
. (Convert-Path -Path $PSScriptRoot/../internal/assertions/Server.Assertions.ps1)

# follow the guidance in Instance.Assertions to add new checks

$Tags = Get-CheckInformation -Check $Check -Group Server -AllChecks $AllChecks -ExcludeCheck $ChecksToExclude
if($IsLinux){
Write-PSFMessage "We cannot run any of the Server tests from linux at the moment" -Level Warning
Return
if ($IsLinux) {
Write-PSFMessage "We cannot run any of the Server tests from linux at the moment" -Level Warning
Return
}
@(Get-ComputerName).ForEach{
$AllServerInfo = Get-AllServerInfo -ComputerName $Psitem -Tags $Tags
Expand Down Expand Up @@ -44,10 +44,10 @@ Return
$pingcount = Get-DbcConfigValue policy.connection.pingcount
$skipping = Get-DbcConfigValue skip.connection.ping
Context "Testing Ping to $psitem" {
It -skip:$skipping "Should have pinged $pingcount times for $psitem" {
It -Skip:$skipping "Should have pinged $pingcount times for $psitem" {
Assert-Ping -AllServerInfo $AllServerInfo -Type Ping
}
It -skip:$skipping "Average response time (ms) should Be less than $pingmsmax (ms) for $psitem" {
It -Skip:$skipping "Average response time (ms) should Be less than $pingmsmax (ms) for $psitem" {
Assert-Ping -AllServerInfo $AllServerInfo -Type Average
}
}
Expand All @@ -63,22 +63,20 @@ Return
}

Describe "Disk Allocation Unit" -Tags DiskAllocationUnit, Medium, $filename {
if($IsCoreCLR){
if ($IsCoreCLR) {
Context "Testing disk allocation unit on $psitem" {
It "Can't run this check on Core on $psitem" -Skip {
$true | Should -BeTrue
}
}
}
else {
} else {
Context "Testing disk allocation unit on $psitem" {
$computerName = $psitem
$excludedisks = Get-DbcConfigValue policy.server.excludeDiskAllocationUnit
@($AllServerInfo.DiskAllocation).Where{$psitem.IsSqlDisk -eq $true}.ForEach{
if($Psitem.Name -in $excludedisks){
@($AllServerInfo.DiskAllocation).Where{ $psitem.IsSqlDisk -eq $true }.ForEach{
if ($Psitem.Name -in $excludedisks) {
$exclude = $true
}
else {
} else {
$exclude = $false
}
It "$($Psitem.Name) Should be set to 64kb on $computerName" -Skip:$exclude {
Expand All @@ -92,7 +90,7 @@ Return
Describe "Non Standard Port" -Tags NonStandardPort, Medium, CIS, $filename {
$skip = Get-DbcConfigValue skip.security.nonstandardport
Context "Checking SQL Server ports on $psitem" {
It "No SQL Server Instances should be configured with port 1433 on $psitem" -skip:$skip {
It "No SQL Server Instances should be configured with port 1433 on $psitem" -Skip:$skip {
Assert-NonStandardPort -AllServerInfo $AllServerInfo
}
}
Expand All @@ -101,7 +99,7 @@ Return
Describe "Server Protocols" -Tags ServerProtocol, Medium, CIS, $filename {
$skip = Get-DbcConfigValue skip.security.serverprotocol
Context "Checking SQL Server protocols on $psitem" {
It "All SQL Server Instances should be configured to run only TCP/IP protocol on $psitem" -skip:$skip {
It "All SQL Server Instances should be configured to run only TCP/IP protocol on $psitem" -Skip:$skip {
Assert-ServerProtocol -AllServerInfo $AllServerInfo
}
}
Expand Down
22 changes: 5 additions & 17 deletions source/dbachecks.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ function Import-ModuleFile {
else {
try {
$ExecutionContext.InvokeCommand.InvokeScript($false, ([scriptblock]::Create([io.file]::ReadAllText($Path))), $null, $null)
}
catch {
} catch {
Write-Warning "Failed to import $Path"
}
}
Expand All @@ -26,31 +25,20 @@ if ((Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WindowsPowerShell\dbacheck
if ((Get-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\WindowsPowerShell\dbachecks\System" -Name "DoDotSource" -ErrorAction Ignore).DoDotSource) { $script:doDotSource = $true }

# Execute Preimport actions
if($IsLinux){
Write-Verbose "Loading preimport in linux"
. Import-ModuleFile -Path "$ModuleRoot/internal/scripts/preimport.ps1"
}else{
. Import-ModuleFile -Path "$ModuleRoot\internal\scripts\preimport.ps1"
}

. Import-ModuleFile -Path (Convert-Path -Path "$ModuleRoot\internal\scripts\preimport.ps1")

# Import all internal functions
foreach ($function in (Get-ChildItem "$ModuleRoot\internal\functions\*.ps1")) {
foreach ($function in (Get-ChildItem (Convert-Path -Path "$ModuleRoot\internal\functions\*.ps1"))) {
. Import-ModuleFile -Path $function.FullName
}

# Import all public functions
foreach ($function in (Get-ChildItem "$ModuleRoot\functions\*.ps1")) {
foreach ($function in (Get-ChildItem (Convert-Path -Path "$ModuleRoot\functions\*.ps1"))) {
. Import-ModuleFile -Path $function.FullName
}

# Execute Postimport actions
if($IsLinux){
Write-Verbose "Loading postimport in linux"
. Import-ModuleFile -Path "$ModuleRoot/internal/scripts/postimport.ps1"
}else{
. Import-ModuleFile -Path "$ModuleRoot\internal\scripts\postimport.ps1"
}
. Import-ModuleFile -Path (Convert-Path -Path "$ModuleRoot\internal\scripts\postimport.ps1")

if (-not (Test-Path Alias:Update-Dbachecks)) { Set-Alias -Scope Global -Name 'Update-Dbachecks' -Value 'Update-DbcRequiredModules' }
$VerbosePreference = "SilentlyContinue"
11 changes: 4 additions & 7 deletions source/functions/Reset-DbcConfig.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
. $script:ModuleRoot/internal/functions/Invoke-ConfigurationScript.ps1
. (Convert-Path -Path $script:ModuleRoot/internal/functions/Invoke-ConfigurationScript.ps1)
<#
.SYNOPSIS
Resets configuration entries to their default values.
Expand Down Expand Up @@ -36,21 +36,18 @@ function Reset-DbcConfig {
if (!$Name) {
# no name provided, get all known dbachecks settings
$resolvedName = (Get-DbcConfig).Name
}
elseif ($Name -match '\*') {
} elseif ($Name -match '\*') {
# wildcard is used, get only the matching settings
$resolvedName = (Get-DbcConfig).Name | Where-Object { $psitem -like $Name }
}
else {
} else {
$resolvedName = $Name
}

@($resolvedName).ForEach{
$localName = $psitem.ToLower()
if (-not (Get-DbcConfig -Name $localName)) {
Stop-PSFFunction -FunctionName Reset-DbcConfig -Message "Setting named $localName does not exist. Use Get-DbcCheck to get the list of supported settings."
}
else {
} else {
Write-PSFMessage -FunctionName Reset-DbcConfig -Message "resetting $localName"
Unregister-PSFConfig -Module dbachecks -Name $localName
[PSFramework.Configuration.ConfigurationHost]::Configurations.Remove("dbachecks.$localName") | Out-Null
Expand Down
Loading