diff --git a/CHANGELOG.md b/CHANGELOG.md index e1395d291..e476f7e96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - SPContentDatabase - Fixed issue where the set method didn't do anything when the Ensure parameter wasn't specified +- SPFarm + - Fixed issue where the resource didn't support precreated databases. - SPFarmAdministrators - Fixed issue in SP2016 where an error was thrown in the Set method since v3.8 - SPFarmSolution diff --git a/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 b/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 index f036fa400..637287a55 100644 --- a/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 @@ -810,10 +810,20 @@ function Set-TargetResource if ($dbStatus.DatabaseExists -eq $true) { - Write-Verbose -Message ("The SharePoint config database " + - "'$($params.FarmConfigDatabaseName)' already exists, so " + - "this server will join the farm.") - $createFarm = $false + if ($dbStatus.DatabaseEmpty -eq $true) + { + Write-Verbose -Message ("The SharePoint config database " + + "'$($params.FarmConfigDatabaseName)' exists but is empty, so " + + "this server will create the farm.") + $createFarm = $true + } + else + { + Write-Verbose -Message ("The SharePoint config database " + + "'$($params.FarmConfigDatabaseName)' already exists, so " + + "this server will join the farm.") + $createFarm = $false + } } elseif ($dbStatus.DatabaseExists -eq $false -and $params.RunCentralAdmin -eq $false) { diff --git a/SharePointDsc/Modules/SharePointDsc.Farm/SPFarm.psm1 b/SharePointDsc/Modules/SharePointDsc.Farm/SPFarm.psm1 index 1f6087317..5f7e521b9 100644 --- a/SharePointDsc/Modules/SharePointDsc.Farm/SPFarm.psm1 +++ b/SharePointDsc/Modules/SharePointDsc.Farm/SPFarm.psm1 @@ -79,8 +79,18 @@ function Get-SPDscConfigDBStatus } } + $configDBempty = $false + if ($configDBexists -eq $true) + { + # Checking if ConfigDB contains any tables + $connection.ChangeDatabase($Database) + $command.CommandText = "SELECT COUNT(*) FROM sys.tables" + $configDBempty = ($command.ExecuteScalar() -eq 0) + } + return @{ DatabaseExists = $configDBexists + DatabaseEmpty = $configDBempty ValidPermissions = $hasPermissions Locked = $lockExists }