Skip to content

Commit

Permalink
AdReplicationSite: Adding description attribute, will create integrat…
Browse files Browse the repository at this point in the history
…ion tests (#501)

- Changes to ADReplicationSite
  - Added 'Description' attribute parameter (issue #500).
  - Added Integration testing (issue #355).
  - Correct value returned for RenameDefaultFirstSiteName (issue #502).
  • Loading branch information
1800Zeta authored and johlju committed Sep 20, 2019
1 parent 314330f commit 83903b2
Show file tree
Hide file tree
Showing 8 changed files with 463 additions and 37 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

- Changes to ADReplicationSite
- Added 'Description' attribute parameter ([issue #500](https://github.com/PowerShell/ActiveDirectoryDsc/issues/500)).
- Added Integration testing ([issue #355](https://github.com/PowerShell/ActiveDirectoryDsc/issues/355)).
- Correct value returned for RenameDefaultFirstSiteName ([issue #502](https://github.com/PowerShell/ActiveDirectoryDsc/issues/502)).

## 4.1.0.0

- Changes to ActiveDirectoryDsc
Expand Down
124 changes: 98 additions & 26 deletions DSCResources/MSFT_ADReplicationSite/MSFT_ADReplicationSite.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,26 @@ function Get-TargetResource
(
[Parameter(Mandatory = $true)]
[System.String]
$Name
$Name,

[Parameter()]
[System.Boolean]
$RenameDefaultFirstSiteName
)

# Get the replication site filtered by it's name. If the site is not
# present, the command will return $null.
Write-Verbose -Message ($script:localizedData.GetReplicationSite -f $Name)
$replicationSite = Get-ADReplicationSite -Filter { Name -eq $Name }
$replicationSite = Get-ADReplicationSite -Filter { Name -eq $Name } -ErrorAction SilentlyContinue

if ($null -eq $replicationSite)
{
Write-Verbose -Message ($script:localizedData.ReplicationSiteAbsent -f $Name)
$returnValue = @{
Ensure = 'Absent'
Name = $Name
RenameDefaultFirstSiteName = ''
Description = $null
RenameDefaultFirstSiteName = $RenameDefaultFirstSiteName
}
}
else
Expand All @@ -44,7 +49,8 @@ function Get-TargetResource
$returnValue = @{
Ensure = 'Present'
Name = $Name
RenameDefaultFirstSiteName = ''
Description = $replicationSite.Description
RenameDefaultFirstSiteName = $RenameDefaultFirstSiteName
}
}

Expand Down Expand Up @@ -82,29 +88,54 @@ function Set-TargetResource

[Parameter()]
[System.Boolean]
$RenameDefaultFirstSiteName = $false
$RenameDefaultFirstSiteName = $false,

[Parameter()]
[System.String]
$Description
)

$getTargetResourceResult = Get-TargetResource -Name $Name -RenameDefaultFirstSiteName $RenameDefaultFirstSiteName

if ($Ensure -eq 'Present')
{
$defaultFirstSiteName = Get-ADReplicationSite -Filter { Name -eq 'Default-First-Site-Name' }

<#
Check if the user specified to rename the Default-First-Site-Name
and if it still exists. If both is true, rename the replication site
instead of creating a new site.
#>
if ($RenameDefaultFirstSiteName -and ($null -ne $defaultFirstSiteName))
if ($getTargetResourceResult.Ensure -eq 'Absent')
{
Write-Verbose -Message ($script:localizedData.AddReplicationSiteDefaultFirstSiteName -f $Name)

Rename-ADObject -Identity $defaultFirstSiteName.DistinguishedName -NewName $Name -ErrorAction Stop
$defaultFirstSiteName = Get-ADReplicationSite -Filter { Name -eq 'Default-First-Site-Name' } -ErrorAction SilentlyContinue

<#
Check if the user specified to rename the Default-First-Site-Name
and if it still exists. If both is true, rename the replication site
instead of creating a new site.
#>
if ($RenameDefaultFirstSiteName -and $null -ne $defaultFirstSiteName)
{
Write-Verbose -Message ($script:localizedData.AddReplicationSiteDefaultFirstSiteName -f $Name)

Rename-ADObject -Identity $defaultFirstSiteName.DistinguishedName -NewName $Name -ErrorAction Stop
}
else
{
Write-Verbose -Message ($script:localizedData.AddReplicationSite -f $Name)

$newADReplicationSiteParameters = @{
Name = $Name
ErrorAction = 'Stop'
}

if ($PSBoundParameters.ContainsKey('Description'))
{
$newADReplicationSiteParameters['Description'] = $Description
}

New-ADReplicationSite @newADReplicationSiteParameters
}
}
else
{
Write-Verbose -Message ($script:localizedData.AddReplicationSite -f $Name)

New-ADReplicationSite -Name $Name -ErrorAction Stop
if ($PSBoundParameters.ContainsKey('Description') -and $getTargetResourceResult.Description -ne $Description)
{
Write-Verbose -Message ($script:localizedData.UpdateReplicationSite -f $Name)
Set-ADReplicationSite -Identity $Name -Description $Description
}
}

Expand All @@ -130,6 +161,11 @@ function Set-TargetResource
.PARAMETER RenameDefaultFirstSiteName
Specify if the Default-First-Site-Name should be renamed, if it exists.
Dafult value is 'false'.
.PARAMETER Description
Specifies a description of the object. This parameter sets the value of
the Description property for the object. The LDAP Display Name
(ldapDisplayName) for this property is 'description'.
#>
function Test-TargetResource
{
Expand All @@ -148,18 +184,54 @@ function Test-TargetResource

[Parameter()]
[System.Boolean]
$RenameDefaultFirstSiteName = $false
$RenameDefaultFirstSiteName = $false,

[Parameter()]
[System.String]
$Description
)

$currentConfiguration = Get-TargetResource -Name $Name
$getTargetResourceResult = Get-TargetResource -Name $Name -RenameDefaultFirstSiteName $RenameDefaultFirstSiteName
$configurationCompliant = $true

if ($currentConfiguration.Ensure -eq $Ensure)
if ($getTargetResourceResult.Ensure -eq 'Absent')
{
Write-Verbose -Message ($script:localizedData.ReplicationSiteInDesiredState -f $Name)
# Site doesn't exist
if ($getTargetResourceResult.Ensure -eq $Ensure)
{
# Site should not exist
Write-Verbose -Message ($script:localizedData.ReplicationSiteInDesiredState -f $Name)
}
else
{
#Site should exist
Write-Verbose -Message ($script:localizedData.ReplicationSiteNotInDesiredState -f $Name)
$configurationCompliant = $false
}
}
else
{
Write-Verbose -Message ($script:localizedData.ReplicationSiteNotInDesiredState -f $Name)
# Site Exists
if ($getTargetResourceResult.Ensure -eq $Ensure)
{
# Site should exist
if ($getTargetResourceResult.Description -ne $Description)
{
Write-Verbose -Message ($script:localizedData.ReplicationSiteNotInDesiredState -f $Name)
$configurationCompliant = $false
}
else
{
Write-Verbose -Message ($script:localizedData.ReplicationSiteInDesiredState -f $Name)
}
}
else
{
# Site should not exist
Write-Verbose -Message ($script:localizedData.ReplicationSiteNotInDesiredState -f $Name)
$configurationCompliant = $false
}
}
return $currentConfiguration.Ensure -eq $Ensure

return $configurationCompliant
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ class MSFT_ADReplicationSite : OMI_BaseResource
[Write, Description("Specifies if the Active Directory replication site should be present or absent. Default value is 'Present'."), ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}] String Ensure;
[Key, Description("Specifies the name of the Active Directory replication site.")] String Name;
[Write, Description("Specifies if the Default-First-Site-Name should be renamed if it exists. Default value is $false.")] Boolean RenameDefaultFirstSiteName;
[Write, Description("Specifies a description of the object. This parameter sets the value of the Description property for the object. The LDAP Display Name (ldapDisplayName) for this property is 'description'.")] String Description;
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ ConvertFrom-StringData @'
ReplicationSitePresent = Replication site '{0}' is present. (ADRS0006)
ReplicationSiteInDesiredState = The replication site '{0}' is in the desired state. (ADRS0007)
ReplicationSiteNotInDesiredState = The replication site '{0}' is not in the desired state. (ADRS0008)
UpdateReplicationSite = The replication site '{0}' needs to be updated.
'@
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
Write - Boolean
Specifies if the Default-First-Site-Name should be renamed if it exists. Default value is $false.

.PARAMETER Description
Write - String
Specifies a description of the object. This parameter sets the value of the Description property for the object. The LDAP Display Name (ldapDisplayName) for this property is 'description'.

.EXAMPLE 1

This configuration will create an Active Directory replication site
Expand Down Expand Up @@ -80,4 +84,22 @@ Configuration ADReplicationSite_RemoveADReplicationSite_Config
}
}

.EXAMPLE 4

This configuration will set the AD Relication Site description for
a site called SeattleSite

Configuration ADReplicationSite_CreateADReplicationSite_Config
{
Import-DscResource -Module ActiveDirectoryDsc

Node localhost
{
ADReplicationSite 'SeattleSite'
{
Ensure = 'Present'
Name = 'Seattle'
Description = 'Seattle Head Office'
}
}
}
Loading

0 comments on commit 83903b2

Please sign in to comment.