-
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 #52 from dsccommunity/DPGroupMembership
DSC_CMDistributionPointGroupMembers Resource merge
- Loading branch information
Showing
8 changed files
with
778 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
311 changes: 311 additions & 0 deletions
311
...DSCResources/DSC_CMDistributionPointGroupMembers/DSC_CMDistributionPointGroupMembers.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,311 @@ | ||
$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 DistributionPoint | ||
Specifies the Distribution Point to modify Distribution Point Group membership. | ||
#> | ||
function Get-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Collections.Hashtable])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[String] | ||
$SiteCode, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[String] | ||
$DistributionPoint | ||
) | ||
|
||
Write-Verbose -Message $script:localizedData.RetrieveSettingValue | ||
Import-ConfigMgrPowerShellModule -SiteCode $SiteCode | ||
Set-Location -Path "$($SiteCode):\" | ||
|
||
$status = Get-CMDistributionPoint -SiteCode $SiteCode -SiteSystemServerName $DistributionPoint | ||
|
||
if ($status) | ||
{ | ||
$dpg = Get-CMDistributionPointGroup | ||
if ($dpg) | ||
{ | ||
$groups = @() | ||
foreach ($group in $dpg) | ||
{ | ||
$groupname = Get-CMDistributionPoint -DistributionPointGroupName $group.Name | ||
$dp = $groupname | Where-Object -FilterScript {$_.NetworkOSPath -eq "\\$DistributionPoint"} | ||
if ($dp) | ||
{ | ||
$groups += $group.Name | ||
} | ||
} | ||
} | ||
|
||
$dpInstall = 'Present' | ||
} | ||
else | ||
{ | ||
$dpInstall = 'Absent' | ||
} | ||
|
||
return @{ | ||
SiteCode = $SiteCode | ||
DistributionPoint = $DistributionPoint | ||
DistributionGroups = $groups | ||
DPStatus = $dpInstall | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
This will set the desired state. | ||
.PARAMETER SiteCode | ||
Specifies the site code for Configuration Manager site. | ||
.PARAMETER DistributionPoint | ||
Specifies the Distribution Point to modify Distribution Point Group membership. | ||
.PARAMETER DistributionGroups | ||
Specifies an array of Distribution Groups to match on the Distribution Point. | ||
.PARAMETER DistributionGroupsToInclude | ||
Specifies an array of Distribution Groups to add to the Distribution Point. | ||
.PARAMETER DistributionGroupsToExclude | ||
Specifies an array of Distribution Groups to remove from the Distribution Point. | ||
#> | ||
function Set-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[String] | ||
$SiteCode, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[String] | ||
$DistributionPoint, | ||
|
||
[Parameter()] | ||
[String[]] | ||
$DistributionGroups, | ||
|
||
[Parameter()] | ||
[String[]] | ||
$DistributionGroupsToInclude, | ||
|
||
[Parameter()] | ||
[String[]] | ||
$DistributionGroupsToExclude | ||
) | ||
|
||
Import-ConfigMgrPowerShellModule -SiteCode $SiteCode | ||
Set-Location -Path "$($SiteCode):\" | ||
|
||
try | ||
{ | ||
$state = Get-TargetResource -SiteCode $SiteCode -DistributionPoint $DistributionPoint | ||
|
||
if ($state.DPStatus -eq 'Absent') | ||
{ | ||
throw ($script:localizedData.DistroPointInstall -f $SiteServerName) | ||
} | ||
|
||
if (-not $PSBoundParameters.ContainsKey('DistributionGroups') -and | ||
$PSBoundParameters.ContainsKey('DistributionGroupsToInclude') -and | ||
$PSBoundParameters.ContainsKey('DistributionGroupsToExclude')) | ||
{ | ||
foreach ($item in $DistributionGroupsToInclude) | ||
{ | ||
if ($DistributionGroupsToExclude -contains $item) | ||
{ | ||
throw ($script:localizedData.ErrorBoth -f $item) | ||
} | ||
} | ||
} | ||
|
||
if ($DistributionGroups -or $DistributionGroupsToInclude -or $DistributionGroupsToExclude) | ||
{ | ||
$distroArray = @{ | ||
Match = $DistributionGroups | ||
Include = $DistributionGroupsToInclude | ||
Exclude = $DistributionGroupsToExclude | ||
CurrentState = $state.DistributionGroups | ||
} | ||
|
||
$distroCompare = Compare-MultipleCompares @distroArray | ||
|
||
if ($distroCompare.Missing) | ||
{ | ||
foreach ($add in $distroCompare.Missing) | ||
{ | ||
if (Get-CMDistributionPointGroup -Name $add) | ||
{ | ||
$addParams = @{ | ||
DistributionPointName = $DistributionPoint | ||
DistributionPointGroupName = $add | ||
} | ||
|
||
Write-Verbose -Message ($script:localizedData.AddDistroGroup -f $add, $DistributionPoint) | ||
Add-CMDistributionPointToGroup @addParams | ||
} | ||
else | ||
{ | ||
[array]$errorMsg += $add | ||
} | ||
} | ||
} | ||
|
||
if ($distroCompare.Remove) | ||
{ | ||
foreach ($remove in $distroCompare.Remove) | ||
{ | ||
$removeParam = @{ | ||
DistributionPointName = $DistributionPoint | ||
DistributionPointGroupName = $remove | ||
} | ||
|
||
Write-Verbose -Message ($script:localizedData.RemoveDistroGroup -f $remove, $DistributionPoint) | ||
Remove-CMDistributionPointFromGroup @removeParam | ||
} | ||
} | ||
} | ||
|
||
if ($errorMsg) | ||
{ | ||
throw ($script:localizedData.ErrorGroup -f ($errorMsg | Out-String)) | ||
} | ||
} | ||
catch | ||
{ | ||
throw $_ | ||
} | ||
finally | ||
{ | ||
Set-Location -Path "$env:temp" | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
This will test the desired state. | ||
.PARAMETER SiteCode | ||
Specifies the site code for Configuration Manager site. | ||
.PARAMETER DistributionPoint | ||
Specifies the Distribution Point to modify Distribution Point Group membership. | ||
.PARAMETER DistributionGroups | ||
Specifies an array of Distribution Groups to match on the Distribution Point. | ||
.PARAMETER DistributionGroupsToInclude | ||
Specifies an array of Distribution Groups to add to the Distribution Point. | ||
.PARAMETER DistributionGroupsToExclude | ||
Specifies an array of Distribution Groups to remove from the Distribution Point. | ||
#> | ||
function Test-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Boolean])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[String] | ||
$SiteCode, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[String] | ||
$DistributionPoint, | ||
|
||
[Parameter()] | ||
[String[]] | ||
$DistributionGroups, | ||
|
||
[Parameter()] | ||
[String[]] | ||
$DistributionGroupsToInclude, | ||
|
||
[Parameter()] | ||
[String[]] | ||
$DistributionGroupsToExclude | ||
) | ||
|
||
Import-ConfigMgrPowerShellModule -SiteCode $SiteCode | ||
Set-Location -Path "$($SiteCode):\" | ||
$state = Get-TargetResource -SiteCode $SiteCode -DistributionPoint $DistributionPoint | ||
$result = $true | ||
|
||
if ($state.DPStatus -eq 'Absent') | ||
{ | ||
Write-Warning -Message ($script:localizedData.DistroPointInstall -f $DistributionPoint) | ||
$result = $false | ||
} | ||
else | ||
{ | ||
if ($PSBoundParameters.ContainsKey('DistributionGroups')) | ||
{ | ||
if ($PSBoundParameters.ContainsKey('DistributionGroupsToInclude') -or | ||
$PSBoundParameters.ContainsKey('DistributionGroupsToExclude')) | ||
{ | ||
Write-Warning -Message $script:localizedData.ParamIgnore | ||
} | ||
} | ||
elseif ($PSBoundParameters.ContainsKey('DistributionGroupsToInclude') -and | ||
$PSBoundParameters.ContainsKey('DistributionGroupsToExclude')) | ||
{ | ||
foreach ($item in $DistributionGroupsToInclude) | ||
{ | ||
if ($DistributionGroupsToExclude -contains $item) | ||
{ | ||
Write-Warning -Message ($script:localizedData.ErrorBoth -f $item) | ||
$result = $false | ||
} | ||
} | ||
} | ||
|
||
if ($DistributionGroups -or $DistributionGroupsToInclude -or $DistributionGroupsToExclude) | ||
{ | ||
$distroArray = @{ | ||
Match = $DistributionGroups | ||
Include = $DistributionGroupsToInclude | ||
Exclude = $DistributionGroupsToExclude | ||
CurrentState = $state.DistributionGroups | ||
} | ||
|
||
$distroCompare = Compare-MultipleCompares @distroArray | ||
|
||
if ($distroCompare.Missing) | ||
{ | ||
Write-Verbose -Message ($script:localizedData.GroupMissing -f $DistributionPoint, ($distroCompare.Missing | Out-String)) | ||
$result = $false | ||
} | ||
|
||
if ($distroCompare.Remove) | ||
{ | ||
Write-Verbose -Message ($script:localizedData.GroupExclude -f $DistributionPoint, ($distroCompare.Remove | Out-String)) | ||
$result = $false | ||
} | ||
} | ||
} | ||
|
||
Write-Verbose -Message ($script:localizedData.TestState -f $result) | ||
Set-Location -Path "$env:temp" | ||
return $result | ||
} |
10 changes: 10 additions & 0 deletions
10
...ources/DSC_CMDistributionPointGroupMembers/DSC_CMDistributionPointGroupMembers.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"), FriendlyName("CMDistributionPointGroupMembers")] | ||
class DSC_CMDistributionPointGroupMembers : OMI_BaseResource | ||
{ | ||
[Key, Description("Specifies the Distribution Point to modify Distribution Point Group membership.")] String DistributionPoint; | ||
[Required, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; | ||
[Write, Description("Specifies an array of Distribution Groups to match on the Distribution Point.")] String DistributionGroups[]; | ||
[Write, Description("Specifies an array of Distribution Groups to add to the Distribution Point.")] String DistributionGroupsToInclude[]; | ||
[Write, Description("Specifies an array of Distribution Groups to remove from the Distribution Point.")] String DistributionGroupsToExclude[]; | ||
[Read, Description("Specifies if the Distribution Point role is installed.")] String DPStatus; | ||
}; |
12 changes: 12 additions & 0 deletions
12
...SC_CMDistributionPointGroupMembers/en-US/DSC_CMDistributionPointGroupMembers.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,12 @@ | ||
ConvertFrom-StringData @' | ||
RetrieveSettingValue = Getting results for Configuration Manager Distribution Point Group members. | ||
DistroPointInstall = The distribution point role on {0} is not installed, run DSC_CMDistibutionPoint to install the role. | ||
GroupMissing = NOTMATCH: {0} is missing Distribution Point Group {1}. | ||
GroupExclude = NOTMATCH: {0} was expecting Distribution Point Group to be absent {1}. | ||
TestState = Test-TargetResource compliance check returned: {0}. | ||
AddDistroGroup = Adding {0} group to Distribution Point {1}. | ||
RemoveDistroGroup = Removing {0} group from Distribution Point {1}. | ||
ParamIgnore = DistributionGroups was specifed, ignoring DistributionGroupsToInclude and DistributionGroupsToExclude. | ||
ErrorGroup = Distribution Groups: {0} does not exist. | ||
ErrorBoth = Distribution Group: {0} is a member of the include group and exclude group. | ||
'@ |
Oops, something went wrong.