Skip to content

Commit

Permalink
Merge pull request #37 from dsccommunity/CMFallbackStatusPoint
Browse files Browse the repository at this point in the history
DSC_CMFallbackStatusPoint: a resource to configure the Fallback Status Point Role
  • Loading branch information
NEllis280 authored Jun 11, 2020
2 parents bb871af + 80f33cc commit b7aa8f9
Show file tree
Hide file tree
Showing 9 changed files with 693 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added CMAssetIntelligencePoint Resource
- Added VSCode Project Settings and PS Script Analyzer rules
- Added Issue and PR template.
- Added CMFallbackStatusPoint Resource

### Changed

Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ Please check out common DSC Community [contributing guidelines](https://dsccommu
management points.
- **CMAssetIntelligencePoint**: Provides a resource for creating and managing
the SCCM Asset Intelligence Synchronization Point role.
- **CMFallbackStatusPoint**: Provides a resource for creating and managing
the SCCM Fallback Status Point role.

### CMAccounts

Expand Down Expand Up @@ -358,3 +360,22 @@ Please check out common DSC Community [contributing guidelines](https://dsccommu

- [CMAssetIntelligencePoint_Absent](Source\Examples\Resources\CMAssetIntelligencePoint\CMAssetIntelligencePoint_Absent.ps1)
- [CMAssetIntelligencePoint_Present](Source\Examples\Resources\CMAssetIntelligencePoint\CMAssetIntelligencePoint_Present.ps1)

### CMFallbackStatusPoint

- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration
Manager site.
- **[String] SiteServerName** _(Key)_: Specifies the Site Server to install
or configure the role on.
- **[UInt32] StateMessageCount** _(Write)_: Specifies the number of state messages
that a fallback status point can send to Configuration Manager within a throttle
interval.
- **[UInt32] ThrottleSec** _(Write)_: Specifies the throttle interval in seconds.
- **[String] Ensure** _(Write)_: Specifies whether the fallback status point is
present or absent.
- Values include: { Present | Absent }

#### CMFallbackStatusPoint Examples

- [CMFallbackStatusPoint_Absent](Source\Examples\Resources\CMFallbackStatusPoint\CMFallbackStatusPoint_Absent.ps1)
- [CMFallbackStatusPoint_Present](Source\Examples\Resources\CMFallbackStatusPoint\CMFallbackStatusPoint_Present.ps1)
3 changes: 2 additions & 1 deletion source/ConfigMgrCBDsc.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
'CMBoundaryGroups'
'CMManagementPoint'
'CMAssetIntelligencePoint'
'CMFallbackStatusPoint'
)

<#
Expand All @@ -64,7 +65,7 @@

# Tags applied to this module. These help with module discovery in online galleries.
Tags = @('DesiredStateConfiguration', 'DSC', 'DSCResourceKit', 'DSCResource', 'ConfigMgrCBDsc','CMAccounts','CMIniFile','Collections',
'CMBoundaries','CMForestDiscovery','ClientStatusSettings','BoundaryGroups','ManagementPoint','CMAssetIntelligencePoint')
'CMBoundaries','CMForestDiscovery','ClientStatusSettings','BoundaryGroups','ManagementPoint','CMAssetIntelligencePoint','CMFallbackStatusPoint')

# A URL to the license for this module.
LicenseUri = 'https://github.com/dsccommunity/ConfigMgrCBDsc/blob/master/LICENSE'
Expand Down
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
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;
};
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}.
'@
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'
}
}
}
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'
}
}
}
Loading

0 comments on commit b7aa8f9

Please sign in to comment.