Skip to content

Commit

Permalink
Merge pull request #1242 from ykuijs/master
Browse files Browse the repository at this point in the history
[SPFarm] Implemented support for precreated databases (partly)
  • Loading branch information
ykuijs committed Sep 29, 2020
2 parents 7d1fe7f + 5c0d277 commit e40d654
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
10 changes: 10 additions & 0 deletions SharePointDsc/Modules/SharePointDsc.Farm/SPFarm.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit e40d654

Please sign in to comment.