-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1406 from ykuijs/master
New resource and various bug fixes
- Loading branch information
Showing
17 changed files
with
1,404 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,5 +26,5 @@ | |
xWebAdministration = '3.1.0' | ||
|
||
# Required for Export of Config | ||
ReverseDSC = "2.0.0.10" | ||
ReverseDSC = "2.0.0.11" | ||
} |
325 changes: 325 additions & 0 deletions
325
SharePointDsc/DSCResources/MSFT_SPSearchCrawlDatabase/MSFT_SPSearchCrawlDatabase.psm1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
10 changes: 10 additions & 0 deletions
10
SharePointDsc/DSCResources/MSFT_SPSearchCrawlDatabase/MSFT_SPSearchCrawlDatabase.schema.mof
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
SharePointDsc/DSCResources/MSFT_SPSearchCrawlDatabase/readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Oops, something went wrong.