From e29ed1e684ce18eaa66317c1a0fa065b89fe59ae Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Fri, 2 Jul 2021 14:34:47 +0200 Subject: [PATCH 1/3] 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; From 2be61dd063d5ecf8cb49df185937a134a946c0d6 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Fri, 2 Jul 2021 14:34:47 +0200 Subject: [PATCH 2/3] 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 990edce5b..be1e2809f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,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 - SPWebAppAuthentication - Updated the description for the new zone setting parameters - SPWebAppClientCallableSettings 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; From 4040dfa79a44dbc9d1690f07608bbd0c3b5cd8ff Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Wed, 25 Aug 2021 09:04:38 +0200 Subject: [PATCH 3/3] Fix unit tests --- .../SharePointDsc.SPSearchServiceApp.Tests.ps1 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchServiceApp.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchServiceApp.Tests.ps1 index afeaa68a7..dca39b9f1 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchServiceApp.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchServiceApp.Tests.ps1 @@ -306,18 +306,22 @@ try Mock -CommandName Get-SPServiceApplication -MockWith { $spServiceApp = [PSCustomObject]@{ - TypeName = "Search Service Application" - DisplayName = $testParams.Name - Name = $testParams.Name - ApplicationPool = @{ Name = $testParams.ApplicationPool } - Database = @{ + TypeName = "Search Service Application" + DisplayName = $testParams.Name + Name = $testParams.Name + ApplicationPool = @{ Name = $testParams.ApplicationPool } + Database = @{ Name = $testParams.DatabaseName NormalizedDataSource = 'SQL01' } - SearchAdminDatabase = @{ + SearchAdminDatabase = @{ Name = $testParams.DatabaseName NormalizedDataSource = 'SQL01' } + AnalyticsReportingDatabases = @{ + Name = $testParams.DatabaseName + '_AnalyticsReportingStore' + NormalizedDataSource = 'SQL01' + } } $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { return @{ FullName = $getTypeFullName }