From e29ed1e684ce18eaa66317c1a0fa065b89fe59ae Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Fri, 2 Jul 2021 14:34:47 +0200 Subject: [PATCH] Fixed issue twith hardcoded database name and space --- CHANGELOG.md | 4 +++ Modules/SharePointDsc/DscResource.Tests | 1 + .../MSFT_SPSearchServiceApp.psm1 | 30 +++++++++++-------- .../SPSearchServiceApp.psm1 | 4 +-- 4 files changed, 25 insertions(+), 14 deletions(-) create mode 160000 Modules/SharePointDsc/DscResource.Tests diff --git a/CHANGELOG.md b/CHANGELOG.md index a09134305..bcdf20673 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - SPFarm - Added parameter SkipRegisterAsDistributedCacheHost +- SPSearchServiceApp + - Fixed an issue if the analytics database where not provisioned with a + hardcoded name + - Fixed an issue if search databases had names containing one or more spaces ### Fixed diff --git a/Modules/SharePointDsc/DscResource.Tests b/Modules/SharePointDsc/DscResource.Tests new file mode 160000 index 000000000..bc9a07d80 --- /dev/null +++ b/Modules/SharePointDsc/DscResource.Tests @@ -0,0 +1 @@ +Subproject commit bc9a07d807c65bbc33d75cf36aa774a73345b809 diff --git a/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/MSFT_SPSearchServiceApp.psm1 b/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/MSFT_SPSearchServiceApp.psm1 index b32237e40..b8f9bc9ff 100644 --- a/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/MSFT_SPSearchServiceApp.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/MSFT_SPSearchServiceApp.psm1 @@ -161,12 +161,15 @@ function Get-TargetResource -User $farmAccount) -eq $false Write-Verbose -Message "Checking Analytics reporting Database" - $analyticsDB = "$($adminDB)_AnalyticsReportingStore" - if ($farmAccountPermissionsNeedCorrecting -eq $false) + foreach ($database in $serviceApp.AnalyticsReportingDatabases) { - $farmAccountPermissionsNeedCorrecting = (Confirm-UserIsDBOwner -SQLServer $dbServer ` - -Database $analyticsDB ` - -User $farmAccount) -eq $false + $analyticsDB = $database.Name + if ($farmAccountPermissionsNeedCorrecting -eq $false) + { + $farmAccountPermissionsNeedCorrecting = (Confirm-UserIsDBOwner -SQLServer $dbServer ` + -Database $analyticsDB ` + -User $farmAccount) -eq $false + } } Write-Verbose -Message "Checking Crawl Database(s)" @@ -539,14 +542,17 @@ function Set-TargetResource } Write-Verbose -Message "Checking and correcting Analytics reporting Database" - $analyticsDB = "$($adminDB)_AnalyticsReportingStore" - if ((Confirm-UserIsDBOwner -SQLServer $dbServer ` - -Database $analyticsDB ` - -User $farmAccount) -eq $false) + foreach ($database in $serviceApp.AnalyticsReportingDatabases) { - Set-UserAsDBOwner -SQLServer $dbServer ` - -Database $analyticsDB ` - -User $farmAccount + $analyticsDB = $database.Name + if ((Confirm-UserIsDBOwner -SQLServer $dbServer ` + -Database $analyticsDB ` + -User $farmAccount) -eq $false) + { + Set-UserAsDBOwner -SQLServer $dbServer ` + -Database $analyticsDB ` + -User $farmAccount + } } Write-Verbose -Message "Checking and correcting Crawl Database(s)" diff --git a/SharePointDsc/Modules/SharePointDsc.Search/SPSearchServiceApp.psm1 b/SharePointDsc/Modules/SharePointDsc.Search/SPSearchServiceApp.psm1 index 11b656d7b..c87363aba 100644 --- a/SharePointDsc/Modules/SharePointDsc.Search/SPSearchServiceApp.psm1 +++ b/SharePointDsc/Modules/SharePointDsc.Search/SPSearchServiceApp.psm1 @@ -43,7 +43,7 @@ function Confirm-UserIsDBOwner $command.Connection = $connection $command.CommandText = @" -USE $Database +USE [$Database] SELECT DP1.name AS DatabaseRoleName, isnull (DP2.name, 'No members') AS DatabaseUserName @@ -116,7 +116,7 @@ function Set-UserAsDBOwner $command.Connection = $connection $command.CommandText = @" -USE $Database +USE [$Database] DECLARE @NewUserName sysname;