Skip to content

Commit

Permalink
Merge pull request #1406 from ykuijs/master
Browse files Browse the repository at this point in the history
New resource and various bug fixes
  • Loading branch information
ykuijs authored May 12, 2022
2 parents f40808f + 0036a0f commit eae0bf0
Show file tree
Hide file tree
Showing 17 changed files with 1,404 additions and 192 deletions.
28 changes: 25 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,36 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- SPWebAppPeoplePickerSettings
- Added the CustomFilter parameter to the resource
- Added the ShortDomainName parameter to the resource
- SharePointDsc
- Added the SPShellAdmin resource to the ReverseDsc export
- Updated ReverseDsc version requirement to 2.0.0.11
- SPFarmPropertyBag
- Added support for boolean and int32 data types
- SPInstall
- Added additional ExitCode for incorrect license key
- SPSearchCrawlDatabase
- New resource
- SPSearchIndexPartition
- Added additional logging to improve troubleshooting
- SPShellAdmin
- Added additional logging to improve troubleshooting
- Added Export logic
- SPWebAppPeoplePickerSettings
- Added the CustomFilter parameter to the resource
- Added the ShortDomainName parameter to the resource

### Fixed

- SharePointDsc
- Fixed incorrect table formatting in the resource table of the Wiki
- SPSearchIndexPartition
- Fixed issue where only one index component was returned after a regression issue in v5.1
- SPSearchServiceApp
- Fixed issue where the database permissions were not corrected for new
search service applications.
- SPShellAdmin
- Fixed issue where the farm account was the owner of the database.
Now including the farm account in those cases.
- SPWebApplication
- Fixed an issue where the Set method tried to use the Parameter SecureSocketsLayer with Set-SPWebApplication on SharePoint Server older than Subscription Edition.
- SPWebAppPeoplePickerSettings
Expand Down
2 changes: 1 addition & 1 deletion RequiredModules.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
xWebAdministration = '3.1.0'

# Required for Export of Config
ReverseDSC = "2.0.0.10"
ReverseDSC = "2.0.0.11"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,325 @@
function Get-TargetResource
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$DatabaseName,

[Parameter(Mandatory = $true)]
[System.String]
$ServiceAppName,

[Parameter()]
[System.String]
$DatabaseServer,

[Parameter()]
[System.Boolean]
$UseSQLAuthentication,

[Parameter()]
[System.Management.Automation.PSCredential]
$DatabaseCredentials,

[Parameter()]
[ValidateSet("Present", "Absent")]
[System.String]
$Ensure = "Present"
)

Write-Verbose -Message "Getting Search Crawl Database '$DatabaseName'"

$result = Invoke-SPDscCommand -Arguments $PSBoundParameters `
-ScriptBlock {
$params = $args[0]

Write-Verbose -Message "Getting Search Service Application $($params.ServiceAppName)"
$ssa = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName `
-Verbose:$false `
-ErrorAction SilentlyContinue

if ($null -eq $ssa)
{
return @{
DatabaseName = $params.DatabaseName
ServiceAppName = $null
DatabaseServer = $null
Ensure = 'Absent'
}
}

Write-Verbose -Message 'Looking for Crawl Databases'
$crawldb = Get-SPEnterpriseSearchCrawlDatabase -SearchApplication $ssa `
-Verbose:$false | Where-Object -FilterScript {
$_.Name -eq $params.DatabaseName
}

if ($null -eq $crawldb)
{
Write-Verbose -Message 'Crawl database not found'
return @{
DatabaseName = $params.DatabaseName
ServiceAppName = $params.ServiceAppName
DatabaseServer = $null
Ensure = 'Absent'
}
}

Write-Verbose -Message 'Crawl database found, returning details'
return @{
DatabaseName = $params.DatabaseName
ServiceAppName = $params.ServiceAppName
DatabaseServer = $crawldb.Database.NormalizedDataSource
Ensure = 'Present'
}
}
return $result
}

function Set-TargetResource
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$DatabaseName,

[Parameter(Mandatory = $true)]
[System.String]
$ServiceAppName,

[Parameter()]
[System.String]
$DatabaseServer,

[Parameter()]
[System.Boolean]
$UseSQLAuthentication,

[Parameter()]
[System.Management.Automation.PSCredential]
$DatabaseCredentials,

[Parameter()]
[ValidateSet("Present", "Absent")]
[System.String]
$Ensure = "Present"
)

Write-Verbose -Message "Setting Search Crawl Database '$DatabaseName'"

$PSBoundParameters.Ensure = $Ensure

$result = Get-TargetResource @PSBoundParameters

if ($result.Ensure -eq "Absent" -and $Ensure -eq "Present")
{
Write-Verbose -Message 'Creating Crawl Database since it does not exist'

Invoke-SPDscCommand -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) `
-ScriptBlock {
$params = $args[0]
$eventSource = $args[1]

Write-Verbose -Message "Getting Search Service Application $($params.ServiceAppName)"
$ssa = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName `
-Verbose:$false `
-ErrorAction SilentlyContinue

if ($null -eq $ssa)
{
$message = 'Specified Search service application could not be found!'
Add-SPDscEvent -Message $message `
-EntryType 'Error' `
-EventID 100 `
-Source $eventSource
throw $message
}

$newParams = @{
SearchApplication = $ssa
DatabaseName = $params.DatabaseName
}

if ($params.ContainsKey('DatabaseServer'))
{
Write-Verbose -Message "DatabaseServer parameter specified. Creating database on server $($params.DatabaseServer)."
$newParams.Add("DatabaseServer", $params.DatabaseServer)
}

if ($params.useSQLAuthentication -eq $true)
{
Write-Verbose -Message "Using SQL authentication to create service application as `$useSQLAuthentication is set to $($params.useSQLAuthentication)."
$newParams.Add("DatabaseUsername", $params.DatabaseCredentials.Username)
$newParams.Add("DatabasePassword", $params.DatabaseCredentials.Password)
}
else
{
Write-Verbose -Message "`$useSQLAuthentication is false or not specified; using default Windows authentication."
}

$null = New-SPEnterpriseSearchCrawlDatabase @newParams -Verbose:$false
Write-Verbose "Crawl database $($params.DatabaseName) created!"
}
}

if ($Ensure -eq "Absent")
{
# The service app should not exit
Write-Verbose -Message "Removing Search Crawl Database '$DatabaseName'"
Invoke-SPDscCommand -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) `
-ScriptBlock {
$params = $args[0]
$eventSource = $args[1]

Write-Verbose -Message "Getting Search Service Application $($params.ServiceAppName)"
$ssa = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName `
-Verbose:$false `
-ErrorAction SilentlyContinue

if ($null -eq $ssa)
{
$message = 'Specified Search service application could not be found!'
Add-SPDscEvent -Message $message `
-EntryType 'Error' `
-EventID 100 `
-Source $eventSource
throw $message
}

Write-Verbose "Removing crawl database '$($params.DatabaseName)'"
Remove-SPEnterpriseSearchCrawlDatabase -SearchApplication $ssa `
-Identity $params.DatabaseName `
-Confirm:$false `
-Verbose:$false
}
}
}

function Test-TargetResource
{
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$DatabaseName,

[Parameter(Mandatory = $true)]
[System.String]
$ServiceAppName,

[Parameter()]
[System.String]
$DatabaseServer,

[Parameter()]
[System.Boolean]
$UseSQLAuthentication,

[Parameter()]
[System.Management.Automation.PSCredential]
$DatabaseCredentials,

[Parameter()]
[ValidateSet("Present", "Absent")]
[System.String]
$Ensure = "Present"
)

Write-Verbose -Message "Testing Search Crawl Database '$DatabaseName'"

$PSBoundParameters.Ensure = $Ensure

$CurrentValues = Get-TargetResource @PSBoundParameters

Write-Verbose -Message "Current Values: $(Convert-SPDscHashtableToString -Hashtable $CurrentValues)"
Write-Verbose -Message "Target Values: $(Convert-SPDscHashtableToString -Hashtable $PSBoundParameters)"

$result = Test-SPDscParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @("Ensure")

Write-Verbose -Message "Test-TargetResource returned $result"

return $result
}

function Export-TargetResource
{
[CmdletBinding()]
[OutputType([System.String])]
param
(
[Parameter()]
[System.String]
$SearchSAName,

[Parameter()]
[System.String[]]
$DependsOn
)

$VerbosePreference = "SilentlyContinue"

$content = ''
$ParentModuleBase = Get-Module "SharePointDsc" -ListAvailable | Select-Object -ExpandProperty Modulebase
$module = Join-Path -Path $ParentModuleBase -ChildPath "\DSCResources\MSFT_SPSearchCrawlDatabase\MSFT_SPSearchCrawlDatabase.psm1" -Resolve

$crawlDBs = Get-SPEnterpriseSearchCrawlDatabase -SearchApplication $SearchSAName `
-Verbose:$false

$j = 1
$totalDBs = $crawlDBs.Count

foreach ($crawlDB in $crawlDBs)
{
$dbName = $crawlDB.Name
Write-Host " -> Scanning Search Crawl Databases [$j/$totalDBs] {$dbName}"
try
{
$params = Get-DSCFakeParameters -ModulePath $module

$partialContent = " SPSearchCrawlDatabase " + $dbName.Replace(" ", "") + "`r`n"
$partialContent += " {`r`n"
$params.DatabaseName = $dbName
$params.ServiceAppName = $SearchSAName
$results = Get-TargetResource @params

$results = Repair-Credentials -results $results

Add-ConfigurationDataEntry -Node "NonNodeData" -Key "DatabaseServer" -Value $results.DatabaseServer -Description "Name of the Database Server associated with the destination SharePoint Farm;"
$results.DatabaseServer = "`$ConfigurationData.NonNodeData.DatabaseServer"

if ($dependsOn)
{
$results.add("DependsOn", $dependsOn)
}

$currentBlock = Get-DSCBlock -Params $results -ModulePath $module
$currentBlock = Convert-DSCStringParamToVariable -DSCBlock $currentBlock -ParameterName "DatabaseServer"
$currentBlock = Convert-DSCStringParamToVariable -DSCBlock $currentBlock -ParameterName "PsDscRunAsCredential"
$partialContent += $currentBlock
$partialContent += " }`r`n"

$j++
$content += $partialContent
}
catch
{
$_
$Global:ErrorLog += "[Search Crawl Database]" + $crawlDB.Name + "`r`n"
$Global:ErrorLog += "$_`r`n`r`n"
}
}

return $content
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[ClassVersion("1.0.0.0"), FriendlyName("SPSearchCrawlDatabase")]
class MSFT_SPSearchCrawlDatabase : OMI_BaseResource
{
[Key, Description("The name of the crawl database")] string DatabaseName;
[Key, Description("The name of the search service application")] string ServiceAppName;
[Write, Description("The server that should host the crawl databases")] string DatabaseServer;
[Write, Description("Should SQL Server authentication be used to connect to the database?")] Boolean UseSQLAuthentication;
[Write, Description("If using SQL authentication, the SQL credentials to use to connect to the instance"), EmbeddedInstance("MSFT_Credential")] String DatabaseCredentials;
[Write, Description("Present if the crawl database should exist, absent if it should not"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure;
};
10 changes: 10 additions & 0 deletions SharePointDsc/DSCResources/MSFT_SPSearchCrawlDatabase/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Description

**Type:** Distributed
**Requires CredSSP:** No

This resource is responsible for managing crawl databases of a Search topology
and is able to add to and remove databases from the topology.

The default value for the Ensure parameter is Present. When not specifying this
parameter, the service application is provisioned.
Loading

0 comments on commit eae0bf0

Please sign in to comment.