-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADDomainControllerProperties: New resource (#474)
- Changes to ActiveDirectoryDsc - New resource ADDomainControllerProperties (issue #301).
- Loading branch information
Showing
16 changed files
with
792 additions
and
6 deletions.
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
197 changes: 197 additions & 0 deletions
197
DSCResources/MSFT_ADDomainControllerProperties/MSFT_ADDomainControllerProperties.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,197 @@ | ||
$script:resourceModulePath = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent | ||
$script:modulesFolderPath = Join-Path -Path $script:resourceModulePath -ChildPath 'Modules' | ||
|
||
$script:localizationModulePath = Join-Path -Path $script:modulesFolderPath -ChildPath 'ActiveDirectoryDsc.Common' | ||
Import-Module -Name (Join-Path -Path $script:localizationModulePath -ChildPath 'ActiveDirectoryDsc.Common.psm1') | ||
|
||
$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_ADDomainControllerProperties' | ||
|
||
<# | ||
.SYNOPSIS | ||
Returns the current state of the properties of the domain controller. | ||
.PARAMETER IsSingleInstance | ||
Specifies the resource is a single instance, the value must be 'Yes'. | ||
#> | ||
function Get-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Collections.Hashtable])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateSet('Yes')] | ||
[System.String] | ||
$IsSingleInstance | ||
) | ||
|
||
Write-Verbose -Message ( | ||
$script:localizedData.RetrievingProperties -f $env:COMPUTERNAME | ||
) | ||
|
||
$getTargetResourceReturnValue = @{ | ||
IsSingleInstance = $IsSingleInstance | ||
ContentFreshness = 0 | ||
} | ||
|
||
$getCimInstanceParameters = @{ | ||
Namespace = 'ROOT/MicrosoftDfs' | ||
Query = 'select MaxOfflineTimeInDays from DfsrMachineConfig' | ||
} | ||
|
||
$getTargetResourceReturnValue['ContentFreshness'] = (Get-CimInstance @getCimInstanceParameters).MaxOfflineTimeInDays | ||
|
||
return $getTargetResourceReturnValue | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Determines if the properties are in the desired state. | ||
.PARAMETER IsSingleInstance | ||
Specifies the resource is a single instance, the value must be 'Yes'. | ||
.PARAMETER ContentFreshness | ||
Specifies the Distributed File System Replication (DFSR) server threshold | ||
after the number of days its content is considered stale (MaxOfflineTimeInDays) | ||
Once the content is considered stale, the Distributed File System Replication | ||
(DFSR) server will no longer be able to replicate. | ||
#> | ||
function Test-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Boolean])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateSet('Yes')] | ||
[System.String] | ||
$IsSingleInstance, | ||
|
||
[Parameter()] | ||
[ValidateNotNullOrEmpty()] | ||
[System.UInt32] | ||
$ContentFreshness | ||
) | ||
|
||
Write-Verbose -Message ( | ||
$script:localizedData.TestConfiguration -f $env:COMPUTERNAME | ||
) | ||
|
||
$compareTargetResourceStateResult = Compare-TargetResourceState @PSBoundParameters | ||
|
||
if ($false -in $compareTargetResourceStateResult.InDesiredState) | ||
{ | ||
Write-Verbose -Message $script:localizedData.DomainControllerNotInDesiredState | ||
|
||
$testTargetResourceReturnValue = $false | ||
} | ||
else | ||
{ | ||
Write-Verbose -Message $script:localizedData.DomainControllerInDesiredState | ||
|
||
$testTargetResourceReturnValue = $true | ||
} | ||
|
||
return $testTargetResourceReturnValue | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Sets the properties on the Active Directory domain controller. | ||
.PARAMETER IsSingleInstance | ||
Specifies the resource is a single instance, the value must be 'Yes'. | ||
.PARAMETER ContentFreshness | ||
Specifies the Distributed File System Replication (DFSR) server threshold | ||
after the number of days its content is considered stale (MaxOfflineTimeInDays) | ||
Once the content is considered stale, the Distributed File System Replication | ||
(DFSR) server will no longer be able to replicate. | ||
#> | ||
function Set-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateSet('Yes')] | ||
[System.String] | ||
$IsSingleInstance, | ||
|
||
[Parameter()] | ||
[ValidateNotNullOrEmpty()] | ||
[System.UInt32] | ||
$ContentFreshness | ||
) | ||
|
||
$compareTargetResourceStateResult = Compare-TargetResourceState @PSBoundParameters | ||
|
||
# Get all properties that are not in desired state. | ||
$propertiesNotInDesiredState = $compareTargetResourceStateResult | Where-Object -FilterScript { | ||
-not $_.InDesiredState | ||
} | ||
|
||
if ($propertiesNotInDesiredState.Where( { $_.ParameterName -eq 'ContentFreshness' })) | ||
{ | ||
Write-Verbose -Message ( | ||
$script:localizedData.ContentFreshnessUpdated -f $ContentFreshness | ||
) | ||
|
||
$setCimInstanceParameters = @{ | ||
Namespace = 'ROOT/MicrosoftDfs' | ||
Query = 'select MaxOfflineTimeInDays from DfsrMachineConfig' | ||
Property = @{ | ||
MaxOfflineTimeInDays = $ContentFreshness | ||
} | ||
|
||
} | ||
|
||
$null = Set-CimInstance @setCimInstanceParameters | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Compares the properties in the current state with the properties of the | ||
desired state and returns a hashtable with the comparison result. | ||
.PARAMETER IsSingleInstance | ||
Specifies the resource is a single instance, the value must be 'Yes'. | ||
.PARAMETER ContentFreshness | ||
Specifies the Distributed File System Replication (DFSR) server threshold | ||
after the number of days its content is considered stale (MaxOfflineTimeInDays) | ||
Once the content is considered stale, the Distributed File System Replication | ||
(DFSR) server will no longer be able to replicate. | ||
#> | ||
function Compare-TargetResourceState | ||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateSet('Yes')] | ||
[System.String] | ||
$IsSingleInstance, | ||
|
||
[Parameter()] | ||
[ValidateNotNullOrEmpty()] | ||
[System.UInt32] | ||
$ContentFreshness | ||
) | ||
|
||
$getTargetResourceParameters = @{ | ||
IsSingleInstance = $IsSingleInstance | ||
} | ||
|
||
$getTargetResourceResult = Get-TargetResource @getTargetResourceParameters | ||
|
||
$compareTargetResourceStateParameters = @{ | ||
CurrentValues = $getTargetResourceResult | ||
DesiredValues = $PSBoundParameters | ||
Properties = @('ContentFreshness') | ||
} | ||
|
||
return Compare-ResourcePropertyState @compareTargetResourceStateParameters | ||
} |
6 changes: 6 additions & 0 deletions
6
DSCResources/MSFT_ADDomainControllerProperties/MSFT_ADDomainControllerProperties.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,6 @@ | ||
[ClassVersion("1.0.0.0"), FriendlyName("ADDomainControllerProperties")] | ||
class MSFT_ADDomainControllerProperties : OMI_BaseResource | ||
{ | ||
[Key, Description("Specifies the resource is a single instance, the value must be 'Yes'."), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance; | ||
[Write, Description("Specifies the Distributed File System Replication (DFSR) server threshold after the number of days its content is considered stale (MaxOfflineTimeInDays). Once the content is considered stale, the Distributed File System Replication (DFSR) server will no longer be able to replicate.")] UInt32 ContentFreshness; | ||
}; |
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,8 @@ | ||
# Description | ||
|
||
This resource enforces the single instance properties of a domain controller. | ||
*Properties that must always have a value, but the value can be changed.* | ||
|
||
## Requirements | ||
|
||
* Target machine must be running Windows Server 2008 R2 or later. |
8 changes: 8 additions & 0 deletions
8
...es/MSFT_ADDomainControllerProperties/en-US/MSFT_ADDomainControllerProperties.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,8 @@ | ||
# culture="en-US" | ||
ConvertFrom-StringData @' | ||
RetrievingProperties = Retrieving the properties for the domain controller '{0}'. (ADDCP0001) | ||
TestConfiguration = Determining the current state of the properties on the domain controller '{0}'. (ADDCP0002) | ||
DomainControllerInDesiredState = The domain controller is in the desired state. (ADDCP0003) | ||
DomainControllerNotInDesiredState = The domain controller is not in the desired state. (ADDCP0004) | ||
ContentFreshnessUpdated = The content freshness property (MaxOfflineTimeInDays) will be updated to {0} days. (ADDCP0005) | ||
'@ |
39 changes: 39 additions & 0 deletions
39
...urces/MSFT_ADDomainControllerProperties/en-US/about_ADDomainControllerProperties.help.txt
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,39 @@ | ||
.NAME | ||
ADDomainControllerProperties | ||
|
||
.DESCRIPTION | ||
This resource enforces the single instance properties of a domain controller. | ||
*Properties that must always have a value, but the value can be changed.* | ||
|
||
## Requirements | ||
|
||
* Target machine must be running Windows Server 2008 R2 or later. | ||
|
||
.PARAMETER IsSingleInstance | ||
Key - String | ||
Allowed values: Yes | ||
Specifies the resource is a single instance, the value must be 'Yes'. | ||
|
||
.PARAMETER ContentFreshness | ||
Write - UInt32 | ||
Specifies the Distributed File System Replication (DFSR) server threshold after the number of days its content is considered stale (MaxOfflineTimeInDays). Once the content is considered stale, the Distributed File System Replication (DFSR) server will no longer be able to replicate. | ||
|
||
.EXAMPLE 1 | ||
|
||
This configuration will set the content freshness to 100 days. | ||
|
||
Configuration ADDomainControllerProperties_SetContentFreshness_Config | ||
{ | ||
Import-DscResource -ModuleName ActiveDirectoryDsc | ||
|
||
node localhost | ||
{ | ||
ADDomainControllerProperties 'ContentFreshness' | ||
{ | ||
IsSingleInstance = 'Yes' | ||
ContentFreshness = 100 | ||
} | ||
} | ||
} | ||
|
||
|
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
36 changes: 36 additions & 0 deletions
36
...DDomainControllerProperties/1-ADDomainControllerProperties_SetContentFreshness_Config.ps1
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,36 @@ | ||
<#PSScriptInfo | ||
.VERSION 1.0.0 | ||
.GUID 924568d9-9764-4277-ab85-5a03b818bf6d | ||
.AUTHOR Microsoft Corporation | ||
.COMPANYNAME Microsoft Corporation | ||
.COPYRIGHT (c) Microsoft Corporation. All rights reserved. | ||
.TAGS DSCConfiguration | ||
.LICENSEURI https://github.com/PowerShell/ActiveDirectoryDsc/blob/master/LICENSE | ||
.PROJECTURI https://github.com/PowerShell/ActiveDirectoryDsc | ||
.ICONURI | ||
.EXTERNALMODULEDEPENDENCIES | ||
.REQUIREDSCRIPTS | ||
.EXTERNALSCRIPTDEPENDENCIES | ||
.RELEASENOTES First version. | ||
.PRIVATEDATA 2016-Datacenter,2016-Datacenter-Server-Core | ||
#> | ||
|
||
#Requires -module ActiveDirectoryDsc | ||
|
||
<# | ||
.DESCRIPTION | ||
This configuration will set the content freshness to 100 days. | ||
#> | ||
Configuration ADDomainControllerProperties_SetContentFreshness_Config | ||
{ | ||
Import-DscResource -ModuleName ActiveDirectoryDsc | ||
|
||
node localhost | ||
{ | ||
ADDomainControllerProperties 'ContentFreshness' | ||
{ | ||
IsSingleInstance = 'Yes' | ||
ContentFreshness = 100 | ||
} | ||
} | ||
} |
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
Oops, something went wrong.