Skip to content

Commit

Permalink
xADDomainController: Added new parameter IsGlobalCatalog (#255)
Browse files Browse the repository at this point in the history
- Changes to xADDomainController
  - Added new parameter to disable or enable the Global Catalog (GC) (issue #75).
  - Fixed a bug with the parameter `InstallationMediaPath` that it would
    not be added if it was specified in a configuration. Now the parameter
    `InstallationMediaPath` is correctly passed to `Install-ADDSDomainController`.
  - Refactored the resource with major code cleanup and localization.
  - Updated unit tests to latest unit test template, and refactored the
    tests for the function 'Set-TargetResource'.
  - Improved test code coverage.
  • Loading branch information
johlju authored May 2, 2019
1 parent da6865d commit d732f41
Show file tree
Hide file tree
Showing 11 changed files with 1,089 additions and 228 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
and [@kungfu71186](https://github.com/kungfu71186)
- Changes to xADReplicationSiteLink
- Make use of the new localization helper functions.
- Changes to xAdDomainController
- Added new parameter to disable or enable the Global Catalog (GC)
([issue #75](https://github.com/PowerShell/xActiveDirectory/issues/75)). [Eric Foskett @Merto410](https://github.com/Merto410)
- Fixed a bug with the parameter `InstallationMediaPath` that it would
not be added if it was specified in a configuration. Now the parameter
`InstallationMediaPath` is correctly passed to `Install-ADDSDomainController`.
- Refactored the resource with major code cleanup and localization.
- Updated unit tests to latest unit test template and refactored the
tests for the function 'Set-TargetResource'.
- Improved test code coverage.

## 2.25.0.0

Expand Down
96 changes: 96 additions & 0 deletions DSCResources/MSFT_xADCommon/MSFT_xADCommon.psm1
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
$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 'DscResource.LocalizationHelper'
Import-Module -Name (Join-Path -Path $script:localizationModulePath -ChildPath 'DscResource.LocalizationHelper.psm1')

data localizedString
{
# culture="en-US"
Expand All @@ -24,6 +30,9 @@ data localizedString
FoundRestoreTargetInRecycleBin = Found object {0} ({1}) in the recycle bin as {2}. Attempting to restore the object.
RecycleBinRestoreSuccessful = Successfully restored object {0} ({1}) from the recycle bin.
AddingGroupMember = Adding member '{0}' from domain '{1}' to AD group '{2}'.
WasExpectingDomainController = The operating system product type code returned 2, which indicates that this is domain controller, but was unable to retrieve the domain controller object. (ADC0001)
FailedEvaluatingDomainController = Could not evaluate if the node is a domain controller. (ADC0002)
'@
}

Expand Down Expand Up @@ -891,3 +900,90 @@ function Add-ADCommonGroupMember
Add-ADGroupMember @Parameters -Members $Members
}
}

<#
.SYNOPSIS
Returns the domain controller object if the node is a domain controller,
otherwise it return $null.
.PARAMETER DomainName
The name of the domain that should contain the domain controller.
.PARAMETER ComputerName
The name of the node to return the domain controller object for.
Defaults to $env:COMPUTERNAME.
.OUTPUTS
If the domain controller is not found, an empty object ($null) is returned.
.NOTES
Throws an exception of Microsoft.ActiveDirectory.Management.ADServerDownException
if the domain cannot be contacted.
#>
function Get-DomainControllerObject
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$DomainName,

[Parameter()]
[System.String]
$ComputerName = $env:COMPUTERNAME,

[Parameter()]
[System.Management.Automation.PSCredential]
$Credential
)

<#
It is not possible to use `-ErrorAction 'SilentlyContinue` on the
cmdlet Get-ADDomainController, it will throw an error regardless.
#>
try
{
$getADDomainControllerParameters = @{
Filter = 'Name -eq "{0}"' -f $ComputerName
Server = $DomainName
}

if ($PSBoundParameters.ContainsKey('Credential'))
{
$getADDomainControllerParameters['Credential'] = $Credential
}

$domainControllerObject = Get-ADDomainController @getADDomainControllerParameters

if (-not $domainControllerObject -and (Test-IsDomainController) -eq $true)
{
$errorMessage = $script:localizedData.WasExpectingDomainController
New-InvalidResultException -Message $errorMessage
}
}
catch
{
$errorMessage = $localizedString.FailedEvaluatingDomainController
New-InvalidOperationException -Message $errorMessage -ErrorRecord $_
}

return $domainControllerObject
}

<#
.SYNOPSIS
Returns $true if the node is a domain controller, otherwise it returns
$false
#>
function Test-IsDomainController
{
[CmdletBinding()]
param
(
)

$operatingSystemInformation = Get-CimInstance -ClassName 'Win32_OperatingSystem'

return $operatingSystemInformation.ProductType -eq 2
}
Loading

0 comments on commit d732f41

Please sign in to comment.