Skip to content

Commit

Permalink
Fix dsccommunity#689, dsccommunity#692 - add ADDomain DomainType support
Browse files Browse the repository at this point in the history
  • Loading branch information
Borgquite committed Feb 13, 2024
1 parent 1f0feb9 commit c13e654
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
26 changes: 25 additions & 1 deletion source/DSCResources/MSFT_ADDomain/MSFT_ADDomain.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function Get-TargetResource
ParentDomainName = $domain.ParentDomain
DomainNetBiosName = $domain.NetBIOSName
DnsDelegationCredential = $null
DomainType = $null
DatabasePath = $serviceNTDS.'DSA Working Directory'
LogPath = $serviceNTDS.'Database log files path'
SysvolPath = $serviceNETLOGON.SysVol -replace '\\sysvol$', ''
Expand All @@ -145,6 +146,7 @@ function Get-TargetResource
ParentDomainName = $ParentDomainName
DomainNetBiosName = $null
DnsDelegationCredential = $null
DomainType = $null
DatabasePath = $null
LogPath = $null
SysvolPath = $null
Expand Down Expand Up @@ -186,6 +188,10 @@ function Get-TargetResource
.PARAMETER DnsDelegationCredential
Credential used for creating DNS delegation.
.PARAMETER DomainType
Specifies whether the domain is a new domain tree in an existing forest ('TreeDomain'),
or a child of an existing domain ('ChildDomain'). Default value is 'ChildDomain'.
.PARAMETER DatabasePath
Path to a directory that contains the domain database.
Expand Down Expand Up @@ -239,6 +245,11 @@ function Test-TargetResource
[System.Management.Automation.PSCredential]
$DnsDelegationCredential,

[Parameter()]
[ValidateSet('ChildDomain', 'TreeDomain')]
[System.String]
$DomainType = 'ChildDomain',

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
Expand Down Expand Up @@ -327,6 +338,10 @@ function Test-TargetResource
.PARAMETER DnsDelegationCredential
Credential used for creating DNS delegation.
.PARAMETER DomainType
Specifies whether the domain is a new domain tree in an existing forest ('TreeDomain'),
or a child of an existing domain ('ChildDomain'). Default value is 'ChildDomain'.
.PARAMETER DatabasePath
Path to a directory that contains the domain database.
Expand Down Expand Up @@ -387,6 +402,11 @@ function Set-TargetResource
[System.Management.Automation.PSCredential]
$DnsDelegationCredential,

[Parameter()]
[ValidateSet('ChildDomain', 'TreeDomain')]
[System.String]
$DomainType = 'ChildDomain',

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
Expand Down Expand Up @@ -474,7 +494,11 @@ function Set-TargetResource
$installADDSParameters['Credential'] = $Credential
$installADDSParameters['NewDomainName'] = $DomainName
$installADDSParameters['ParentDomainName'] = $ParentDomainName
$installADDSParameters['DomainType'] = 'ChildDomain'

if ($PSBoundParameters.ContainsKey('DomainType'))
{
$installADDSParameters['DomainType'] = $DomainType
}

if ($PSBoundParameters.ContainsKey('DomainNetBiosName'))
{
Expand Down
1 change: 1 addition & 0 deletions source/DSCResources/MSFT_ADDomain/MSFT_ADDomain.schema.mof
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class MSFT_ADDomain : OMI_BaseResource
[Write, Description("Fully qualified domain name (FQDN) of the parent domain.")] String ParentDomainName;
[Write, Description("NetBIOS name for the new domain.")] String DomainNetBiosName;
[Write, Description("Credential used for creating DNS delegation."), EmbeddedInstance("MSFT_Credential")] String DnsDelegationCredential;
[Write, Description("Specifies whether the domain is a new domain tree in an existing forest ('TreeDomain'), or a child of an existing domain ('ChildDomain'). Default value is 'ChildDomain'."), ValueMap{"ChildDomain", "TreeDomain"}, Values{"ChildDomain", "TreeDomain"}] String DomainType;
[Write, Description("Path to a directory that contains the domain database.")] String DatabasePath;
[Write, Description("Path to a directory for the log file that will be written.")] String LogPath;
[Write, Description("Path to a directory where the Sysvol file will be written.")] String SysvolPath;
Expand Down
4 changes: 3 additions & 1 deletion tests/Unit/MSFT_ADDomain.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ try
Describe 'ADDomain\Set-TargetResource' {
$mockDomainName = 'present.com'
$mockParentDomainName = 'parent.com'
$mockDomainType = 'ChildDomain'
$mockDomainNetBIOSNameName = 'PRESENT'
$mockDomainForestMode = 'WinThreshold'
$mockPath = 'TestPath'
Expand All @@ -283,6 +284,7 @@ try
ParentDomainName = $mockParentDomainName
Credential = $mockAdministratorCredential
SafeModeAdministratorPassword = $mockSafemodeCredential
DomainType = $mockDomainType
}

Mock -CommandName Get-TargetResource -MockWith { return $mockADDomainAbsent }
Expand Down Expand Up @@ -385,7 +387,7 @@ try
Set-TargetResource @setTargetResourceDomainParams

Assert-MockCalled -CommandName Install-ADDSDomain `
-ParameterFilter { $DomainType -eq 'ChildDomain' }
-ParameterFilter { $DomainType -eq $mockDomainType }
}

It 'Calls "Install-ADDSDomain" with "SafeModeAdministratorPassword"' {
Expand Down

0 comments on commit c13e654

Please sign in to comment.