DSCResources/myAdSite/myAdSite.psm1
Import-Module $PSScriptRoot\..\myAdHelper.psm1 -Verbose:$false function Get-TargetResource { [CmdletBinding()] [OutputType([System.Collections.Hashtable])] param ( [parameter(Mandatory = $true)] [System.String]$Name, [System.String]$Location, [System.String]$Description, [System.Boolean]$InterSiteTopologyGeneration, [System.Boolean]$IntraSiteTopologyGeneration, [System.Boolean]$Protected, [System.Management.Automation.PSCredential]$Credential ) $SitesDN = ReplacePartitionTokens -Identity "CN=Sites,%%configuration%%" -Credential $Credential Write-Verbose "SitesDN: $SitesDN" myGetAdObject -Filter "objectClass -eq 'site' -and Name -eq '$Name'" -SearchBase $SitesDN -Properties @('location', 'description') -Credential $Credential } function Set-TargetResource { [CmdletBinding()] param ( [parameter(Mandatory = $true)] [System.String]$Name, [System.String]$Location, [System.String]$Description, [System.Boolean]$InterSiteTopologyGeneration = $true, [System.Boolean]$IntraSiteTopologyGeneration = $true, [System.Boolean]$Protected, [System.Management.Automation.PSCredential]$Credential ) $Site = Get-TargetResource @PSBoundParameters if ($Site) { Set-ADReplicationSite -Identity $Name -Replace @{ location = "$Location" } -Credential $Credential -Description $Description -AutomaticInterSiteTopologyGenerationEnabled $InterSiteTopologyGeneration -AutomaticTopologyGenerationEnabled $IntraSiteTopologyGeneration } else { New-ADReplicationSite -Name $Name -Description $Description -protectedFromAccidentalDeletion $Protected -OtherAttributes @{ location = "$Location" } -Credential $Credential -AutomaticInterSiteTopologyGenerationEnabled $InterSiteTopologyGeneration -AutomaticTopologyGenerationEnabled $IntraSiteTopologyGeneration } } function Test-TargetResource { [CmdletBinding()] [OutputType([System.Boolean])] param ( [parameter(Mandatory = $true)] [System.String]$Name, [System.String]$Location, [System.String]$Description, [System.Boolean]$InterSiteTopologyGeneration, [System.Boolean]$IntraSiteTopologyGeneration, [System.Boolean]$Protected, [System.Management.Automation.PSCredential]$Credential ) $result = $true $Site = Get-TargetResource @PSBoundParameters if ($Site) { if ($($Site.Location) -ne $Location) { $result = $false } if ($($Site.Description) -ne $Description) { $result = $false } } else { $result = $false } $result } Export-ModuleMember -Function *-TargetResource |