-
Notifications
You must be signed in to change notification settings - Fork 8
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 #37 from dsccommunity/CMFallbackStatusPoint
DSC_CMFallbackStatusPoint: a resource to configure the Fallback Status Point Role
- Loading branch information
Showing
9 changed files
with
693 additions
and
1 deletion.
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
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
269 changes: 269 additions & 0 deletions
269
source/DSCResources/DSC_CMFallbackStatusPoint/DSC_CMFallbackStatusPoint.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,269 @@ | ||
$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' | ||
$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' | ||
|
||
Import-Module -Name $script:dscResourceCommonPath | ||
Import-Module -Name $script:configMgrResourcehelper | ||
|
||
$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' | ||
|
||
<# | ||
.SYNOPSIS | ||
This will return a hashtable of results. | ||
.PARAMETER SiteCode | ||
Specifies the site code for Configuration Manager site. | ||
.PARAMETER SiteServerName | ||
Specifies the Site Server to install or configure the role on. | ||
.Notes | ||
This must be ran on the Primary servers to install the fallback status point role. | ||
The Primary server computer account must be in the local | ||
administrators group to perform the install. | ||
#> | ||
function Get-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Collections.Hashtable])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[String] | ||
$SiteCode, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[String] | ||
$SiteServerName | ||
) | ||
|
||
Write-Verbose -Message $script:localizedData.RetrieveSettingValue | ||
Import-ConfigMgrPowerShellModule -SiteCode $SiteCode | ||
Set-Location -Path "$($SiteCode):\" | ||
|
||
$fspProps = (Get-CMFallbackStatusPoint -SiteCode $SiteCode -SiteSystemServerName $SiteServerName).Props | ||
|
||
if ($fspProps) | ||
{ | ||
foreach ($fspProp in $fspProps) | ||
{ | ||
switch ($fspProp.PropertyName) | ||
{ | ||
'Throttle Count' { $throttleCount = $fspProp.Value } | ||
'Throttle Interval' { $throttleInterval = $fspProp.Value/1000 } | ||
} | ||
} | ||
$status = 'Present' | ||
} | ||
else | ||
{ | ||
$status = 'Absent' | ||
} | ||
|
||
return @{ | ||
SiteServerName = $SiteServerName | ||
SiteCode = $SiteCode | ||
StateMessageCount = $throttleCount | ||
ThrottleSec = $throttleInterval | ||
Ensure = $status | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
This will set the desired state. | ||
.PARAMETER SiteCode | ||
Specifies a site code for the Configuration Manager site. | ||
.PARAMETER SiteServerName | ||
Specifies the Site Server to install or configure the role on. | ||
.PARAMETER StateMessageCount | ||
Specifies the number of state messages that a fallback status point can send to Configuration Manager within a throttle interval. | ||
.PARAMETER ThrottleSec | ||
Specifies the throttle interval in seconds. | ||
.PARAMETER Ensure | ||
Specifies whether the fallback status point is present or absent. | ||
.Notes | ||
This must be ran on the Primary servers to install the fallback status point role. | ||
The Primary server computer account must be in the local | ||
administrators group to perform the install. | ||
#> | ||
function Set-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[String] | ||
$SiteCode, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[String] | ||
$SiteServerName, | ||
|
||
[Parameter()] | ||
[ValidateRange(100,100000)] | ||
[UInt32] | ||
$StateMessageCount, | ||
|
||
[Parameter()] | ||
[ValidateRange(60,86400)] | ||
[UInt32] | ||
$ThrottleSec, | ||
|
||
[Parameter()] | ||
[ValidateSet('Present','Absent')] | ||
[String] | ||
$Ensure = 'Present' | ||
) | ||
|
||
Import-ConfigMgrPowerShellModule -SiteCode $SiteCode | ||
Set-Location -Path "$($SiteCode):\" | ||
$state = Get-TargetResource -SiteCode $SiteCode -SiteServerName $SiteServerName | ||
|
||
try | ||
{ | ||
if ($Ensure -eq 'Present') | ||
{ | ||
if ($state.Ensure -eq 'Absent') | ||
{ | ||
if ($null -eq (Get-CMSiteSystemServer -SiteCode $SiteCode -SiteSystemServerName $SiteServerName)) | ||
{ | ||
Write-Verbose -Message ($script:localizedData.SiteServerRole -f $SiteServerName) | ||
New-CMSiteSystemServer -SiteCode $SiteCode -SiteSystemServerName $SiteServerName | ||
} | ||
|
||
Write-Verbose -Message ($script:localizedData.AddFSPRole -f $SiteServerName) | ||
Add-CMFallbackStatusPoint -SiteSystemServerName $SiteServerName -SiteCode $SiteCode | ||
} | ||
|
||
$evalList = @('StateMessageCount','ThrottleSec') | ||
|
||
foreach ($param in $PSBoundParameters.GetEnumerator()) | ||
{ | ||
if ($evalList -contains $param.key) | ||
{ | ||
if ($param.Value -ne $state[$param.key]) | ||
{ | ||
Write-Verbose -Message ($script:localizedData.SettingValue -f $param.Key, $param.Value) | ||
$buildingParams += @{ | ||
$param.Key = $param.Value | ||
} | ||
} | ||
} | ||
} | ||
|
||
if ($buildingParams) | ||
{ | ||
Set-CMFallbackStatusPoint -SiteSystemServerName $SiteServerName -SiteCode $SiteCode @buildingParams | ||
} | ||
} | ||
elseif ($state.Ensure -eq 'Present') | ||
{ | ||
Write-Verbose -Message ($script:localizedData.RemoveFSPRole -f $SiteServerName) | ||
Remove-CMFallbackStatusPoint -SiteSystemServerName $SiteServerName -SiteCode $SiteCode | ||
} | ||
} | ||
catch | ||
{ | ||
throw $_ | ||
} | ||
finally | ||
{ | ||
Set-Location -Path "$env:temp" | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
This will test the desired state. | ||
.PARAMETER SiteCode | ||
Specifies a site code for the Configuration Manager site. | ||
.PARAMETER SiteServerName | ||
Specifies the Site Server to install or configure the role on. | ||
.PARAMETER StateMessageCount | ||
Specifies the number of state messages that a fallback status point can send to Configuration Manager within a throttle interval. | ||
.PARAMETER ThrottleSec | ||
Specifies the throttle interval in seconds. | ||
.PARAMETER Ensure | ||
Specifies whether the fallback status point is present or absent. | ||
.Notes | ||
This must be ran on the Primary servers to install the fallback status point role. | ||
The Primary server computer account must be in the local | ||
administrators group to perform the install. | ||
#> | ||
function Test-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Boolean])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[String] | ||
$SiteCode, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[String] | ||
$SiteServerName, | ||
|
||
[Parameter()] | ||
[ValidateRange(100,100000)] | ||
[UInt32] | ||
$StateMessageCount, | ||
|
||
[Parameter()] | ||
[ValidateRange(60,86400)] | ||
[UInt32] | ||
$ThrottleSec, | ||
|
||
[Parameter()] | ||
[ValidateSet('Present','Absent')] | ||
[String] | ||
$Ensure = 'Present' | ||
) | ||
|
||
Import-ConfigMgrPowerShellModule -SiteCode $SiteCode | ||
Set-Location -Path "$($SiteCode):\" | ||
$state = Get-TargetResource -SiteCode $SiteCode -SiteServerName $SiteServerName | ||
$result = $true | ||
|
||
if ($Ensure -eq 'Present') | ||
{ | ||
if ($state.Ensure -eq 'Absent') | ||
{ | ||
Write-Verbose -Message ($script:localizedData.FSPNotInstalled -f $SiteServerName) | ||
$result = $false | ||
} | ||
else | ||
{ | ||
$testParams = @{ | ||
CurrentValues = $state | ||
DesiredValues = $PSBoundParameters | ||
ValuesToCheck = @('StateMessageCount','ThrottleSec') | ||
} | ||
|
||
$result = Test-DscParameterState @testParams -Verbose -TurnOffTypeChecking | ||
} | ||
} | ||
elseif ($state.Ensure -eq 'Present') | ||
{ | ||
Write-Verbose -Message ($script:localizedData.FSPAbsent -f $SiteServerName) | ||
$result = $false | ||
} | ||
|
||
Write-Verbose -Message ($script:localizedData.TestState -f $result) | ||
Set-Location -Path "$env:temp" | ||
return $result | ||
} | ||
|
||
Export-ModuleMember -Function *-TargetResource |
9 changes: 9 additions & 0 deletions
9
source/DSCResources/DSC_CMFallbackStatusPoint/DSC_CMFallbackStatusPoint.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,9 @@ | ||
[ClassVersion("1.0.0"), FriendlyName("CMFallbackStatusPoint")] | ||
class DSC_CMFallbackStatusPoint: OMI_BaseResource | ||
{ | ||
[Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; | ||
[Key, Description("Specifies the Site Server to install or configure the role on.")] String SiteServerName; | ||
[Write, Description("Specifies the number of state messages that a fallback status point can send to Configuration Manager within a throttle interval.")] UInt32 StateMessageCount; | ||
[Write, Description("Specifies the throttle interval in seconds.")] UInt32 ThrottleSec; | ||
[Write, Description("Specifies whether the fallback status point is present or absent."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; | ||
}; |
10 changes: 10 additions & 0 deletions
10
source/DSCResources/DSC_CMFallbackStatusPoint/en-US/DSC_CMFallbackStatusPoint.strings.psd1
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 @@ | ||
ConvertFrom-StringData @' | ||
RetrieveSettingValue = Getting information for the specified Fallback Status Point. | ||
FSPNotInstalled = Fallback Status Point is not installed on server: {0}. | ||
FSPAbsent = {0} Fallback Status Point expected absent returned Present. | ||
SiteServerRole = {0} is not currently a site system server adding site system role. | ||
TestState = Test-TargetResource compliance check returned: {0}. | ||
AddFSPRole = Adding Fallback Status Point role to {0}. | ||
SettingValue = Setting value: {0} to {1}. | ||
RemoveFSPRole = Removing Fallback Status Point role from {0}. | ||
'@ |
18 changes: 18 additions & 0 deletions
18
source/Examples/Resources/CMFallbackStatusPoint/CMFallbackStatusPoint_Absent.ps1
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,18 @@ | ||
<# | ||
.SYNOPSIS | ||
A DSC configuration script to remove a fallback status point from Configuration Manager. | ||
#> | ||
Configuration Example | ||
{ | ||
Import-DscResource -ModuleName ConfigMgrCBDsc | ||
|
||
Node localhost | ||
{ | ||
CMFallbackStatusPoint ExampleSettings | ||
{ | ||
SiteCode = 'Lab' | ||
SiteServerName = 'FSP01.contoso.com' | ||
Ensure = 'Absent' | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
source/Examples/Resources/CMFallbackStatusPoint/CMFallbackStatusPoint_Present.ps1
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,20 @@ | ||
<# | ||
.SYNOPSIS | ||
A DSC configuration script to add a fallback status point to Configuration Manager. | ||
#> | ||
Configuration Example | ||
{ | ||
Import-DscResource -ModuleName ConfigMgrCBDsc | ||
|
||
Node localhost | ||
{ | ||
CMFallbackStatusPoint ExampleSettings | ||
{ | ||
SiteCode = 'Lab' | ||
SiteServerName = 'FSP01.contoso.com' | ||
Ensure = 'Present' | ||
StateMessageCount = '10000' | ||
ThrottleSec = '3600' | ||
} | ||
} | ||
} |
Oops, something went wrong.