Skip to content

Commit

Permalink
Merge pull request #1402 from ykuijs/master
Browse files Browse the repository at this point in the history
  • Loading branch information
ykuijs committed Mar 25, 2022
2 parents 1ee98a0 + 059ca7e commit 139e5f7
Show file tree
Hide file tree
Showing 16 changed files with 683 additions and 84 deletions.
18 changes: 16 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- SPFarmPropertyBag
- Added support for boolean and int32 data types
- SPInstall
- Added additional ExitCode for incorrect license key
- SPShellAdmin
- Added additional logging to improve troubleshooting

### Fixed

- SPSearchServiceApp
- Fixed issue where the database permissions were not corrected for new
search service applications.
- SPWebApplication
- Fixed an issue where the Set method tried to use the Parameter SecureSocketsLayer with Set-SPWebApplication on SharePoint Server older than Subscription Edition.
- Fixed an issue where the Set method tried to use the Parameter SecureSocketsLayer with
Set-SPWebApplication on SharePoint Server older than Subscription Edition.

## [5.1.0] - 2022-02-24

Expand Down Expand Up @@ -182,7 +196,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
created, resulting in other errors.
- SPSearchTopology
- 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.
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@

This resource is responsible for configuring the distributed cache client
settings. It only accepts Ensure='Present' as a key. The resource can
configure the following cache components: DistributedLogonTokenCache,
DistributedViewStateCache, DistributedAccessCache,
DistributedActivityFeedCache, DistributedActivityFeedLMTCache,
DistributedBouncerCache, DistributedDefaultCache, DistributedSearchCache,
DistributedSecurityTrimmingCache, and DistributedServerToAppServerAccessTokenCache.
configure the following cache components:
- DistributedLogonTokenCache
- DistributedViewStateCache
- DistributedAccessCache
- DistributedActivityFeedCache
- DistributedActivityFeedLMTCache
- DistributedBouncerCache
- DistributedDefaultCache
- DistributedSearchCache
- DistributedSecurityTrimmingCache
- DistributedServerToAppServerAccessTokenCache.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

This resource is responsible for provisioning the distributed cache to the
service it runs on. This is required in your farm on at least one server (as
the behavior of SPCreateFarm and SPJoinFarm is to not enroll every server as a
cache server). The service will be provisioned or de-provisioned based on the
the behavior of SPFarm is to not enroll every server as a cache server).
The service will be provisioned or de-provisioned based on the
Ensure property, and when provisioned the CacheSizeInMB property and
ServiceAccount property will be used to configure it. The property
createFirewallRules is used to determine if exceptions should be added to the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,51 @@ function Get-TargetResource
[System.String]
$Value,

[Parameter()]
[ValidateSet("Boolean", "String", "Int32")]
[System.String]
$ParameterType = 'String',

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

Write-Verbose -Message "Looking for SPFarm property '$Name'"
Write-Verbose -Message "Getting SPFarm property '$Key'"

if ($ParameterType -eq 'Boolean' -and $Value -notin @('True', 'False'))
{
$message = ("Value can only be True or False when ParameterType is Boolean. Current value: $Value")
Add-SPDscEvent -Message $message `
-EntryType 'Error' `
-EventID 100 `
-Source $MyInvocation.MyCommand.Source
throw $message
}

$int = 0
if ($ParameterType -eq 'Int32' -and [Int32]::TryParse($Value, [ref]$int) -eq $false)
{
$message = ("Value has to be a number when ParameterType is Int32. Current value: $Value")
Add-SPDscEvent -Message $message `
-EntryType 'Error' `
-EventID 100 `
-Source $MyInvocation.MyCommand.Source
throw $message
}

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

try
{
$spFarm = Get-SPFarm -ErrorAction SilentlyContinue
$spFarm = Get-SPFarm -ErrorAction SilentlyContinue -Verbose:$false
}
catch
{
Write-Verbose -Message ("No local SharePoint farm was detected.")
Write-Verbose -Message ('No local SharePoint farm was detected.')
return @{
Key = $params.Key
Value = $null
Expand All @@ -45,25 +71,53 @@ function Get-TargetResource
if ($spFarm.Properties.Contains($params.Key) -eq $true)
{
$localEnsure = "Present"
$currentValue = $spFarm.Properties[$params.Key]
$value = $spFarm.Properties[$params.Key]
switch ($value.GetType().Name)
{
'Boolean'
{
$currentType = 'Boolean'
if ($value)
{
$currentValue = 'true'
}
else
{
$currentValue = 'false'
}
}
'String'
{
$currentType = 'String'
$currentValue = $spFarm.Properties[$params.Key]
}
'Int32'
{
$currentType = 'Int32'
$currentValue = $spFarm.Properties[$params.Key].ToString()
}
}
}
else
{
$localEnsure = "Absent"
$currentValue = $null
$currentType = ""
$localEnsure = "Absent"
}
}
}
else
{
$currentValue = $null
$currentType = ""
$localEnsure = 'Absent'
}

return @{
Key = $params.Key
Value = $currentValue
Ensure = $localEnsure
Key = $params.Key
Value = $currentValue
ParameterType = $currentType
Ensure = $localEnsure
}
}
return $result
Expand All @@ -82,13 +136,39 @@ function Set-TargetResource()
[System.String]
$Value,

[Parameter()]
[ValidateSet("Boolean", "String", "Int32")]
[System.String]
$ParameterType = 'String',

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

Write-Verbose -Message "Setting SPFarm property '$Name'"
Write-Verbose -Message "Setting SPFarm property '$Key'"

if ($ParameterType -eq 'Boolean' -and $Value -notin @('True', 'False'))
{
$message = ("Value can only be True or False when ParameterType is Boolean. Current value: $Value")
Add-SPDscEvent -Message $message `
-EntryType 'Error' `
-EventID 100 `
-Source $MyInvocation.MyCommand.Source
throw $message
}

$int = 0
if ($ParameterType -eq 'Int32' -and [Int32]::TryParse($Value, [ref]$int) -eq $false)
{
$message = ("Value has to be a number when ParameterType is Int32. Current value: $Value")
Add-SPDscEvent -Message $message `
-EntryType 'Error' `
-EventID 100 `
-Source $MyInvocation.MyCommand.Source
throw $message
}

Invoke-SPDscCommand -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) `
-ScriptBlock {
Expand All @@ -97,11 +177,11 @@ function Set-TargetResource()

try
{
$spFarm = Get-SPFarm -ErrorAction SilentlyContinue
$spFarm = Get-SPFarm -ErrorAction SilentlyContinue -Verbose:$false
}
catch
{
$message = "No local SharePoint farm was detected."
$message = 'No local SharePoint farm was detected.'
Add-SPDscEvent -Message $message `
-EntryType 'Error' `
-EventID 100 `
Expand All @@ -114,17 +194,31 @@ function Set-TargetResource()
if ($params.Value)
{
Write-Verbose -Message "Adding property '$params.Key'='$params.value' to SPFarm.properties"
$spFarm.Properties[$params.Key] = $params.Value
switch ($params.ParameterType)
{
'Boolean'
{
$spFarm.Properties[$params.Key] = [System.Convert]::ToBoolean($params.Value)
}
'String'
{
$spFarm.Properties[$params.Key] = $params.Value
}
'Int32'
{
$spFarm.Properties[$params.Key] = [Int32]::Parse($params.Value)
}
}
$spFarm.Update()
}
else
{
Write-Warning -Message 'Ensure = Present, value parameter cannot be null'
Write-Warning -Message 'Ensure = Present, parameter Value cannot be null'
}
}
else
{
Write-Verbose -Message "Removing property '$params.Key' from SPFarm.properties"
Write-Verbose -Message "Removing property '$($params.Key)' from SPFarm.properties"

$spFarm.Properties.Remove($params.Key)
$spFarm.Update()
Expand All @@ -146,13 +240,18 @@ function Test-TargetResource()
[System.String]
$Value,

[Parameter()]
[ValidateSet("Boolean", "String", "Int32")]
[System.String]
$ParameterType = 'String',

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

Write-Verbose -Message "Testing SPFarm property '$Name'"
Write-Verbose -Message "Testing SPFarm property '$Key'"

$CurrentValues = Get-TargetResource @PSBoundParameters

Expand All @@ -162,7 +261,7 @@ function Test-TargetResource()
$result = Test-SPDscParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @('Ensure', 'Key', 'Value')
-ValuesToCheck @('Ensure', 'Key', 'Value', 'ParameterType')

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ class MSFT_SPFarmPropertyBag : OMI_BaseResource
{
[Key, Description("The key of the SPFarm property bag")] string Key;
[Write, Description("Value of the SPfarm property bag")] String Value;
[Write, Description("Type of the data in the Value parameter"), ValueMap{"Boolean","String","Int32"}, Values{"Boolean","String","Int32"}] string ParameterType;
[Write, Description("Set to present to ensure the SPfarm property exists, or absent to ensure it is removed"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure;
};
4 changes: 4 additions & 0 deletions SharePointDsc/DSCResources/MSFT_SPFarmPropertyBag/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
This resource is used to work with SharePoint Property Bags at the farm level.
The account that runs this resource must be a farm administrator.

The Value parameter must be in string format, but with the ParameterType
parameter, you can specify of which data type the data in Value is: String,
Boolean or Int32. See the examples for more information.

The default value for the Ensure parameter is Present. When not specifying this
parameter, the property bag is configured.
9 changes: 9 additions & 0 deletions SharePointDsc/DSCResources/MSFT_SPInstall/MSFT_SPInstall.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,15 @@ function Set-TargetResource
throw $message
}
}
30030
{
$message = "SharePoint install failed: Incorrect license key!"
Add-SPDscEvent -Message $message `
-EntryType 'Error' `
-EventID 100 `
-Source $MyInvocation.MyCommand.Source
throw $message
}
30203
{
$message = "SharePoint install failed, license terms are not accepted."
Expand Down

0 comments on commit 139e5f7

Please sign in to comment.