Skip to content

Commit

Permalink
Merge pull request #122 from claudiospizzi/xADDomainController-Return…
Browse files Browse the repository at this point in the history
…Path

xADDomainController return path
  • Loading branch information
BerheAbrha authored Nov 18, 2016
2 parents 2676f79 + f9ac0ee commit 4eea17b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ function Get-TargetResource
if ($dc.Domain -eq $DomainName)
{
Write-Verbose -Message "Current node '$($dc.Name)' is already a domain controller for domain '$($dc.Domain)'."
$returnValue.Ensure = $true
$returnValue.SiteName = $dc.Site

$serviceNTDS = Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\NTDS\Parameters'
$serviceNETLOGON = Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters'

$returnValue.Ensure = $true
$returnValue.DatabasePath = $serviceNTDS.'DSA Working Directory'
$returnValue.LogPath = $serviceNTDS.'Database log files path'
$returnValue.SysvolPath = $serviceNETLOGON.SysVol -replace '\\sysvol$', ''
$returnValue.SiteName = $dc.Site
}
}
catch
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ Setting an ODJ Request file path for a configuration that creates a computer acc

### 2.14.0.0
* xADDomainController: Adds Site option.
* xADDomainController: Populate values for DatabasePath, LogPath and SysvolPath during Get-TargetResource.

### 2.13.0.0
* Converted AppVeyor.yml to pull Pester from PSGallery instead of Chocolatey
Expand Down
56 changes: 44 additions & 12 deletions Tests/Unit/MSFT_xADDomainController.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ $TestEnvironment = Initialize-TestEnvironment `
try
{
#region Pester Test Initialization
$correctSiteName = 'PresentSite'
$incorrectSiteName = 'IncorrectSite'
$correctDomainName = 'present.com'
$correctDomainName = 'present.com'
$testAdminCredential = [System.Management.Automation.PSCredential]::Empty
$correctDatabasePath = 'C:\Windows\NTDS'
$correctLogPath = 'C:\Windows\NTDS'
$correctSysvolPath = 'C:\Windows\SYSVOL'
$correctSiteName = 'PresentSite'
$incorrectSiteName = 'IncorrectSite'

$testDefaultParams = @{
DomainAdministratorCredential = $testAdminCredential
Expand Down Expand Up @@ -56,17 +59,43 @@ try

#region Function Get-TargetResource
Describe -Tag 'xADDomainController' "$($Script:DSCResourceName)\Get-TargetResource" {
It 'Returns current "SiteName"' {
Mock Get-ADDomain { return $true } @commonMockParams
Mock Get-ADDomainController {
return $stubDomainController = @{
Site = 'PresentSite'
Domain = 'present.com'
}
} @commonMockParams

$result = Get-TargetResource @testDefaultParams -DomainName $correctDomainName -SiteName $correctSiteName
Mock Get-ADDomain { return $true } @commonMockParams
Mock Get-ADDomainController {
return $stubDomainController = @{
Site = 'PresentSite'
Domain = 'present.com'
}
} @commonMockParams
Mock Get-ItemProperty -ParameterFilter { $Path -eq 'HKLM:\SYSTEM\CurrentControlSet\Services\NTDS\Parameters' } {
return @{
'Database log files path' = 'C:\Windows\NTDS'
'DSA Working Directory' = 'C:\Windows\NTDS'
}
} @commonMockParams
Mock Get-ItemProperty -ParameterFilter { $Path -eq 'HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters' } {
return @{
'SysVol' = 'C:\Windows\SYSVOL\sysvol'
}
} @commonMockParams

It 'Returns current "DatabasePath"' {
$result = Get-TargetResource @testDefaultParams -DomainName $correctDomainName
$result.DatabasePath | Should Be $correctDatabasePath
}

It 'Returns current "LogPath"' {
$result = Get-TargetResource @testDefaultParams -DomainName $correctDomainName
$result.LogPath | Should Be $correctLogPath
}

It 'Returns current "SysvolPath"' {
$result = Get-TargetResource @testDefaultParams -DomainName $correctDomainName
$result.SysvolPath | Should Be $correctSysvolPath
}

It 'Returns current "SiteName"' {
$result = Get-TargetResource @testDefaultParams -DomainName $correctDomainName
$result.SiteName | Should Be $correctSiteName
}
}
Expand Down Expand Up @@ -98,6 +127,8 @@ try
Mock Get-ADDomain { return $true }
Mock Get-ADDomainController { return $stubDomainController }
Mock Test-ADReplicationSite { return $true }
Mock Get-ItemProperty { return @{} }

$result = Test-TargetResource @testDefaultParams -DomainName $correctDomainName -SiteName $correctSiteName

$result | Should Be $false
Expand All @@ -113,6 +144,7 @@ try
Mock Get-ADDomain { return $true }
Mock Get-ADDomainController { return $stubDomainController }
Mock Test-ADReplicationSite { return $true }
Mock Get-ItemProperty { return @{} }

$result = Test-TargetResource @testDefaultParams -DomainName $correctDomainName -SiteName $correctSiteName

Expand Down

0 comments on commit 4eea17b

Please sign in to comment.