Skip to content

Commit

Permalink
Merge pull request #1342 from ykuijs/bugfix
Browse files Browse the repository at this point in the history
Fixed #990 and added logging to SPSearchServiceApp
  • Loading branch information
ykuijs authored Aug 31, 2021
2 parents 106cade + 7de1e46 commit 8214236
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- SPSearchServiceApp
- Added additional logging at checking db permissions
- SPWebAppHttpThrottlingMonitor
- Added new resource to manage web application Http Throttling Monitor settings

Expand Down Expand Up @@ -42,6 +44,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed issue where an error was thrown if the specified RootDirectory didn't exist on the
current server but did exist on the target server.
- Fixed issue with using FQDNs instead of NetBIOS server names.
- SPSite
- Implemented workaround to prevent issue with creating site collections immediately after
farm creation (Error "Invalid field name. {cbb92da4-fd46-4c7d-af6c-3128c2a5576e}")
- SPWorkManagementServiceApp
- Updated links to Docs instead of old TechNet

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,26 @@ function Get-TargetResource

Write-Verbose -Message "Checking Admin Database"
$adminDB = $serviceApp.SearchAdminDatabase.Name

Write-Verbose -Message "Checking Admin Database: $adminDB"
$farmAccountPermissionsNeedCorrecting = (Confirm-UserIsDBOwner -SQLServer $dbServer `
-Database $adminDB `
-User $farmAccount) -eq $false
Write-Verbose -Message "Farm Account Permissions Need Correcting: $farmAccountPermissionsNeedCorrecting"

Write-Verbose -Message "Checking Analytics reporting Database"
foreach ($database in $serviceApp.AnalyticsReportingDatabases)
{
$analyticsDB = $database.Name

Write-Verbose -Message "Checking Analytics reporting Database: $analyticsDB"
if ($farmAccountPermissionsNeedCorrecting -eq $false)
{
$farmAccountPermissionsNeedCorrecting = (Confirm-UserIsDBOwner -SQLServer $dbServer `
-Database $analyticsDB `
-User $farmAccount) -eq $false
}
Write-Verbose -Message "Farm Account Permissions Need Correcting: $farmAccountPermissionsNeedCorrecting"
}

Write-Verbose -Message "Checking Crawl Database(s)"
Expand All @@ -179,9 +185,12 @@ function Get-TargetResource
{
$crawlDB = $database.Database.Name
$dbServer = $database.Database.NormalizedDataSource

Write-Verbose -Message "Checking Crawl Database: $crawlDB"
$farmAccountPermissionsNeedCorrecting = (Confirm-UserIsDBOwner -SQLServer $dbServer `
-Database $crawlDB `
-User $farmAccount) -eq $false
Write-Verbose -Message "Farm Account Permissions Need Correcting: $farmAccountPermissionsNeedCorrecting"
}
}

Expand All @@ -192,9 +201,12 @@ function Get-TargetResource
{
$linksDB = $database.Database.Name
$dbServer = $database.Database.NormalizedDataSource

Write-Verbose -Message "Checking Links Database: $linksDB"
$farmAccountPermissionsNeedCorrecting = (Confirm-UserIsDBOwner -SQLServer $dbServer `
-Database $linksDB `
-User $farmAccount) -eq $false
Write-Verbose -Message "Farm Account Permissions Need Correcting: $farmAccountPermissionsNeedCorrecting"
}
}

Expand Down
41 changes: 40 additions & 1 deletion SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,46 @@ function Set-TargetResource
{
Write-Verbose -Message ("Starting New-SPSite with the following parameters: " + `
"$(Convert-SPDscHashtableToString $params)")
$site = New-SPSite @params
#$site = New-SPSite @params

$paramsList = $params.GetEnumerator() | Where-Object {
$_.Key -ne "Verbose"
} | ForEach-Object {
if ($_.Key -is [Switch])
{
"-$($_.Key):$($_.Value)"
}
else
{
"-$($_.Key) '$($_.Value)'"
}
}
$paramsStr = $paramsList -join " "
$installedVersion = Get-SPDscInstalledProductVersion
if ($installedVersion.ProductMajorPart -eq 15 -or $installedVersion.ProductBuildPart -le 12999)
{
$newSPSiteCmd = "Add-PSSnapin Microsoft.SharePoint.PowerShell;"
}
else
{
$newSPSiteCmd = "Import-Module SharePointServer -Verbose:`$false -WarningAction SilentlyContinue;"
}

$newSPSiteCmd += "New-SPSite " + $paramsStr
Write-Verbose "Running command: $newSPSiteCmd"

$result = Start-Process -Wait `
-NoNewWindow `
-FilePath "powershell.exe" `
-ArgumentList @("-command", "$newSPSiteCmd") `
-PassThru
if ($result.ExitCode -ne 0)
{
throw ("[ERROR] An error during site creation. Exit code '$($result.ExitCode)' " + `
"was returned. Please check ULS log for more info")
}
$site = Get-SPSite -Identity $params.Url -ErrorAction SilentlyContinue

if ($CreateDefaultGroups -eq $true)
{
$doCreateDefaultGroups = $true
Expand Down
10 changes: 8 additions & 2 deletions tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ try
InModuleScope -ModuleName $script:DSCResourceFullName -ScriptBlock {
Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture {
BeforeAll {
Invoke-Command -Scriptblock $Global:SPDscHelper.InitializeScript -NoNewScope
Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope

# Initialize tests
try
Expand Down Expand Up @@ -185,6 +185,12 @@ try
}

Mock -CommandName Get-SPSite -MockWith { return $null }

Mock -CommandName Start-Process -MockWith {
return @{
ExitCode = 0
}
}
}

It "Should return OwnerAlias=Null from the get method" {
Expand All @@ -197,7 +203,7 @@ try

It "Should create a new site from the set method" {
Set-TargetResource @testParams
Assert-MockCalled New-SPSite
Assert-MockCalled Start-Process
}
}

Expand Down

0 comments on commit 8214236

Please sign in to comment.