Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AdReplicationSite: Adding description attribute, will create integration tests #501

Merged
merged 17 commits into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@
needs the feature Recycle Bin enabled ([issue #498](https://github.com/PowerShell/xActiveDirectory/issues/498)).
- Updated integration test to be able to catch when a computer account
cannot be restored.
- 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.0.0.0

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