Skip to content

Commit

Permalink
Merge pull request #166 from PowerShell/release-v0.10
Browse files Browse the repository at this point in the history
Release v0.10
  • Loading branch information
KarolKaczmarek committed Feb 1, 2016
2 parents e932922 + a3ee0d8 commit c5812dc
Show file tree
Hide file tree
Showing 87 changed files with 5,048 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ function Get-TargetResource
[parameter(Mandatory = $true)] [System.String] $Passphrase,
[parameter(Mandatory = $true)] [System.String] $AdminContentDatabaseName,
[parameter(Mandatory = $false)] [System.UInt32] $CentralAdministrationPort,
[parameter(Mandatory = $false)] [ValidateSet("Application","Custom","DistributedCache","Search","SingleServer","SingleServerFarm","SpecialLoad","WebFrontEnd")] $ServerRole
[parameter(Mandatory = $false)] [System.String] [ValidateSet("Application","Custom","DistributedCache","Search","SingleServer","SingleServerFarm","SpecialLoad","WebFrontEnd")] $ServerRole
)

Write-Verbose -Message "Checking for local SP Farm"

if ($null -ne $ServerRole -and (Get-xSharePointInstalledProductVersion).FileMajorPart -ne 16) {
if (($PSBoundParameters.ContainsKey("ServerRole") -eq $true) -and (Get-xSharePointInstalledProductVersion).FileMajorPart -ne 16) {
throw [Exception] "Server role is only supported in SharePoint 2016."
}

Expand Down Expand Up @@ -66,10 +66,10 @@ function Set-TargetResource
[parameter(Mandatory = $true)] [System.String] $Passphrase,
[parameter(Mandatory = $true)] [System.String] $AdminContentDatabaseName,
[parameter(Mandatory = $false)] [System.UInt32] $CentralAdministrationPort,
[parameter(Mandatory = $false)] [ValidateSet("Application","Custom","DistributedCache","Search","SingleServer","SingleServerFarm","SpecialLoad","WebFrontEnd")] $ServerRole
[parameter(Mandatory = $false)] [System.String] [ValidateSet("Application","Custom","DistributedCache","Search","SingleServer","SingleServerFarm","SpecialLoad","WebFrontEnd")] $ServerRole
)

if ($null -ne $ServerRole -and (Get-xSharePointInstalledProductVersion).FileMajorPart -ne 16) {
if (($PSBoundParameters.ContainsKey("ServerRole") -eq $true) -and (Get-xSharePointInstalledProductVersion).FileMajorPart -ne 16) {
throw [Exception] "Server role is only supported in SharePoint 2016."
}

Expand Down Expand Up @@ -128,10 +128,10 @@ function Test-TargetResource
[parameter(Mandatory = $true)] [System.String] $Passphrase,
[parameter(Mandatory = $true)] [System.String] $AdminContentDatabaseName,
[parameter(Mandatory = $false)] [System.UInt32] $CentralAdministrationPort,
[parameter(Mandatory = $false)] [ValidateSet("Application","Custom","DistributedCache","Search","SingleServer","SingleServerFarm","SpecialLoad","WebFrontEnd")] $ServerRole
[parameter(Mandatory = $false)] [System.String] [ValidateSet("Application","Custom","DistributedCache","Search","SingleServer","SingleServerFarm","SpecialLoad","WebFrontEnd")] $ServerRole
)

if ($null -ne $ServerRole -and (Get-xSharePointInstalledProductVersion).FileMajorPart -ne 16) {
if (($PSBoundParameters.ContainsKey("ServerRole") -eq $true) -and (Get-xSharePointInstalledProductVersion).FileMajorPart -ne 16) {
throw [Exception] "Server role is only supported in SharePoint 2016."
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
function Get-TargetResource
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[parameter(Mandatory = $true)] [System.String] $Name,
[parameter(Mandatory = $true)] [System.Boolean] $Enabled,
[parameter(Mandatory = $false)] [ValidateSet("All Servers","Any Server")] [System.String] $RuleScope,
[parameter(Mandatory = $false)] [ValidateSet("Hourly","Daily","Weekly","Monthly","OnDemandOnly")] [System.String] $Schedule,
[parameter(Mandatory = $false)] [System.Boolean] $FixAutomatically,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
)

Write-Verbose -Message "Getting Health Rule configuration settings"

$result = Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]

try {
$spFarm = Get-SPFarm
} catch {
Write-Verbose -Verbose "No local SharePoint farm was detected. Health Analyzer Rule settings will not be applied"
return $null
}

$caWebapp = Get-SPwebapplication -includecentraladministration | where {$_.IsAdministrationWebApplication}
if ($null -eq $caWebapp) {
Write-Verbose -Verbose "Unable to locate central administration website"
return $null
}

# Get CA SPWeb
$caWeb = Get-SPWeb($caWebapp.Url)
$healthRulesList = $caWeb.Lists | ? { $_.BaseTemplate -eq "HealthRules"}

if ($healthRulesList -ne $null) {
$spQuery = New-Object Microsoft.SharePoint.SPQuery
$querytext = "<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>$($params.Name)</Value></Eq></Where>"
$spQuery.Query = $querytext
$results = $healthRulesList.GetItems($spQuery)
if ($results.Count -eq 1) {
$item = $results[0]

return @{
# Set the Health Analyzer Rule settings
Name = $params.Name
Enabled = $item["HealthRuleCheckEnabled"]
RuleScope = $item["HealthRuleScope"]
Schedule = $item["HealthRuleSchedule"]
FixAutomatically = $item["HealthRuleAutoRepairEnabled"]
InstallAccount = $params.InstallAccount
}
} else {
Write-Verbose -Verbose "Unable to find specified Health Analyzer Rule"
return $null
}
} else {
Write-Verbose -Verbose "Unable to locate Health Analyzer Rules list"
return $null
}
}

return $result
}


function Set-TargetResource
{
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)] [System.String] $Name,
[parameter(Mandatory = $true)] [System.Boolean] $Enabled,
[parameter(Mandatory = $false)] [ValidateSet("All Servers","Any Server")] [System.String] $RuleScope,
[parameter(Mandatory = $false)] [ValidateSet("Hourly","Daily","Weekly","Monthly","OnDemandOnly")] [System.String] $Schedule,
[parameter(Mandatory = $false)] [System.Boolean] $FixAutomatically,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
)

Write-Verbose -Message "Setting Health Analyzer Rule configuration settings"

Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]

try {
$spFarm = Get-SPFarm
} catch {
throw "No local SharePoint farm was detected. Health Analyzer Rule settings will not be applied"
return
}

$caWebapp = Get-SPwebapplication -includecentraladministration | where {$_.IsAdministrationWebApplication}
if ($null -eq $caWebapp) {
throw "No Central Admin web application was found. Health Analyzer Rule settings will not be applied"
return
}

# Get Central Admin SPWeb
$caWeb = Get-SPWeb($caWebapp.Url)
$healthRulesList = $caWeb.Lists | ? { $_.BaseTemplate -eq "HealthRules"}

if ($healthRulesList -ne $null) {
$spQuery = New-Object Microsoft.SharePoint.SPQuery
$querytext = "<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>$($params.Name)</Value></Eq></Where>"
$spQuery.Query = $querytext
$results = $healthRulesList.GetItems($spQuery)
if ($results.Count -eq 1) {
$item = $results[0]

$item["HealthRuleCheckEnabled"] = $params.Enabled
if ($params.ContainsKey("RuleScope")) { $item["HealthRuleScope"] = $params.RuleScope }
if ($params.ContainsKey("Schedule")) { $item["HealthRuleSchedule"] = $params.Schedule }
if ($params.ContainsKey("FixAutomatically")) { $item["HealthRuleAutoRepairEnabled"] = $params.FixAutomatically }

$item.Update()
} else {
throw "Could not find specified Health Analyzer Rule. Health Analyzer Rule settings will not be applied"
return
}
} else {
throw "Could not find Health Analyzer Rules list. Health Analyzer Rule settings will not be applied"
return
}
}
}


function Test-TargetResource
{
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
[parameter(Mandatory = $true)] [System.String] $Name,
[parameter(Mandatory = $true)] [System.Boolean] $Enabled,
[parameter(Mandatory = $false)] [ValidateSet("All Servers","Any Server")] [System.String] $RuleScope,
[parameter(Mandatory = $false)] [ValidateSet("Hourly","Daily","Weekly","Monthly","OnDemandOnly")] [System.String] $Schedule,
[parameter(Mandatory = $false)] [System.Boolean] $FixAutomatically,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
)

Write-Verbose -Message "Testing Health Analyzer rule configuration settings"
$CurrentValues = Get-TargetResource @PSBoundParameters

if ($null -eq $CurrentValues) { return $false }

return Test-xSharePointSpecificParameters -CurrentValues $CurrentValues -DesiredValues $PSBoundParameters
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
**Description**

This resource is used to configure Health Analyzer rules for the local farm.
The resource is able to enable/disable and configure the specified rule.

**Example**

xSPHealthAnalyzerRuleState DisableDiskSpaceRule
{
Name = "Drives are at risk of running out of free space."
Enabled = $true
RuleScope = "All Servers"
Schedule = "Daily"
FixAutomatically = $false
InstallAccount = $InstallAccount
}
*/

[ClassVersion("1.0.0.0"), FriendlyName("xSPHealthAnalyzerRuleState")]
class MSFT_xSPHealthAnalyzerRuleState : OMI_BaseResource
{
[Key] String Name;
[Required] Boolean Enabled;
[Write, ValueMap{"All Servers","Any Server"}, Values{"All Servers","Any Server"}] String RuleScope;
[Write, ValueMap{"Hourly","Daily","Weekly","Monthly","OnDemandOnly"}, Values{"Hourly","Daily","Weekly","Monthly","OnDemandOnly"}] String Schedule;
[Write] Boolean FixAutomatically;
[Write, EmbeddedInstance("MSFT_Credential")] String InstallAccount;
};

Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ function Get-TargetResource
[parameter(Mandatory = $true)] [System.String] $DatabaseServer,
[parameter(Mandatory = $true)] [System.String] $Passphrase,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount,
[parameter(Mandatory = $false)] [ValidateSet("Application","Custom","DistributedCache","Search","SingleServer","SingleServerFarm","SpecialLoad","WebFrontEnd")] $ServerRole
[parameter(Mandatory = $false)] [System.String] [ValidateSet("Application","Custom","DistributedCache","Search","SingleServer","SingleServerFarm","SpecialLoad","WebFrontEnd")] $ServerRole
)

Write-Verbose -Message "Checking for local SP Farm"

if ($null -ne $ServerRole -and (Get-xSharePointInstalledProductVersion).FileMajorPart -ne 16) {
if (($PSBoundParameters.ContainsKey("ServerRole") -eq $true) -and (Get-xSharePointInstalledProductVersion).FileMajorPart -ne 16) {
throw [Exception] "Server role is only supported in SharePoint 2016."
}

Expand Down Expand Up @@ -51,12 +51,12 @@ function Set-TargetResource
[parameter(Mandatory = $true)] [System.String] $DatabaseServer,
[parameter(Mandatory = $true)] [System.String] $Passphrase,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount,
[parameter(Mandatory = $false)] [ValidateSet("Application","Custom","DistributedCache","Search","SingleServer","SingleServerFarm","SpecialLoad","WebFrontEnd")] $ServerRole
[parameter(Mandatory = $false)] [System.String] [ValidateSet("Application","Custom","DistributedCache","Search","SingleServer","SingleServerFarm","SpecialLoad","WebFrontEnd")] $ServerRole
)

Write-Verbose -Message "Joining existing farm configuration database"

if ($null -ne $ServerRole -and (Get-xSharePointInstalledProductVersion).FileMajorPart -ne 16) {
if (($PSBoundParameters.ContainsKey("ServerRole") -eq $true) -and (Get-xSharePointInstalledProductVersion).FileMajorPart -ne 16) {
throw [Exception] "Server role is only supported in SharePoint 2016."
}

Expand All @@ -76,8 +76,12 @@ function Set-TargetResource
Write-Verbose -Message "Detected Version: SharePoint 2013"
}
16 {
Write-Verbose -Message "Detected Version: SharePoint 2016"
$joinFarmArgs.Add("LocalServerRole", "Custom")
if ($params.ContainsKey("ServerRole") -eq $true) {
Write-Verbose -Message "Detected Version: SharePoint 2016 - configuring server as $($params.ServerRole)"
$joinFarmArgs.Add("LocalServerRole", $params.ServerRole)
} else {
Write-Verbose -Message "Detected Version: SharePoint 2016 - no server role provided, configuring server without a specific role"
}
}
Default {
throw [Exception] "An unknown version of SharePoint (Major version $_) was detected. Only versions 15 (SharePoint 2013) or 16 (SharePoint 2016) are supported."
Expand Down Expand Up @@ -113,10 +117,10 @@ function Test-TargetResource
[parameter(Mandatory = $true)] [System.String] $DatabaseServer,
[parameter(Mandatory = $true)] [System.String] $Passphrase,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount,
[parameter(Mandatory = $false)] [ValidateSet("Application","Custom","DistributedCache","Search","SingleServer","SingleServerFarm","SpecialLoad","WebFrontEnd")] $ServerRole
[parameter(Mandatory = $false)] [System.String] [ValidateSet("Application","Custom","DistributedCache","Search","SingleServer","SingleServerFarm","SpecialLoad","WebFrontEnd")] $ServerRole
)

if ($null -ne $ServerRole -and (Get-xSharePointInstalledProductVersion).FileMajorPart -ne 16) {
if (($PSBoundParameters.ContainsKey("ServerRole") -eq $true) -and (Get-xSharePointInstalledProductVersion).FileMajorPart -ne 16) {
throw [Exception] "Server role is only supported in SharePoint 2016."
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ class MSFT_xSPSearchTopology : OMI_BaseResource
[Required] String AnalyticsProcessing[];
[Required] String QueryProcessing[];
[Required] String IndexPartition[];
[Write] String FirstPartitionDirectory;
[Required] String FirstPartitionDirectory;
[Write, EmbeddedInstance("MSFT_Credential")] String InstallAccount;
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MSFT_xSPSecureStoreServiceApp : OMI_BaseResource
[Write, EmbeddedInstance("MSFT_Credential")] String DatabaseCredentials;
[Write] string DatabaseName;
[Write] string DatabaseServer;
[Write, ValueMap {"Windows","SQL"}, Values{"Windows","SQL"}] string DatabaseAuthenticationType;
[Write, ValueMap{"Windows","SQL"}, Values{"Windows","SQL"}] string DatabaseAuthenticationType;
[Write] string FailoverDatabaseServer;
[Write] boolean PartitionMode;
[Write] boolean Sharing;
Expand Down
Loading

0 comments on commit c5812dc

Please sign in to comment.