Skip to content

Commit

Permalink
xActiveDirectory: MSFT_xADCommon.ps1 is renamed to MSFT_xADCommon.psm1 (
Browse files Browse the repository at this point in the history
dsccommunity#202)

- The helper function script file MSFT_xADCommon.ps1 was renamed to MSFT_xADCommon.psm1
  to be a module script file instead. This makes it possible to report code coverage for the helper 
  functions (issue dsccommunity#201).
  • Loading branch information
johlju authored Jun 11, 2018
1 parent f6d8e72 commit 7f7bb4e
Show file tree
Hide file tree
Showing 10 changed files with 706 additions and 694 deletions.
601 changes: 0 additions & 601 deletions DSCResources/MSFT_xADCommon/MSFT_xADCommon.ps1

This file was deleted.

603 changes: 600 additions & 3 deletions DSCResources/MSFT_xADCommon/MSFT_xADCommon.psm1

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions DSCResources/MSFT_xADComputer/MSFT_xADComputer.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
$moduleRoot = Split-Path -Path $MyInvocation.MyCommand.Path -Parent

## Import the common AD functions
$adCommonFunctions = Join-Path `
-Path (Split-Path -Path $PSScriptRoot -Parent) `
-ChildPath '\MSFT_xADCommon\MSFT_xADCommon.psm1'
Import-Module -Name $adCommonFunctions

#region LocalizedData
$culture = 'en-us'
if (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath $PSUICulture))
Expand Down Expand Up @@ -512,10 +519,4 @@ function Set-TargetResource

} #end function Set-TargetResource

## Import the common AD functions
$adCommonFunctions = Join-Path `
-Path (Split-Path -Path $PSScriptRoot -Parent) `
-ChildPath '\MSFT_xADCommon\MSFT_xADCommon.ps1';
. $adCommonFunctions;

Export-ModuleMember -Function *-TargetResource
44 changes: 23 additions & 21 deletions DSCResources/MSFT_xADDomain/MSFT_xADDomain.psm1
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Import the common AD functions
$adCommonFunctions = Join-Path `
-Path (Split-Path -Path $PSScriptRoot -Parent) `
-ChildPath '\MSFT_xADCommon\MSFT_xADCommon.psm1'
Import-Module -Name $adCommonFunctions

# Localized messages
data localizedData
{
Expand All @@ -7,7 +13,7 @@ data localizedData
InvalidDomainError = Computer is a member of the wrong domain?!
ExistingDomainMemberError = Computer is already a domain member. Cannot create a new '{0}' domain?
InvalidCredentialError = Domain '{0}' is available, but invalid credentials were supplied.
QueryDomainWithLocalCredential = Computer is a domain member; querying domain '{0}' using local credential ...
QueryDomainWithCredential = Computer is a workgroup member; querying for domain '{0}' using supplied credential ...
DomainFound = Active Directory domain '{0}' found.
Expand Down Expand Up @@ -35,14 +41,14 @@ data localizedData
.NOTES
The tracking file is currently output to the environment's temp directory.
This file is NOT removed when a configuration completes, so if another call to a xADDomain
resource with the same domain name occurs in the same environment, this file will already
be present.
This is so that when another call is made to the same resource, the resource will not
attempt to promote the machine to a domain controller again (which would cause an error).
If the resource should be promoted to a domain controller once again, you must first remove
this file from the environment's temp directory (usually C:\Temp).
Expand Down Expand Up @@ -95,7 +101,7 @@ function Get-TargetResource
[Parameter()] [ValidateNotNullOrEmpty()]
[String] $SysvolPath
)

Assert-Module -ModuleName 'ADDSDeployment';
$domainFQDN = Resolve-DomainFQDN -DomainName $DomainName -ParentDomainName $ParentDomainName;
$isDomainMember = Test-DomainMember;
Expand All @@ -104,7 +110,7 @@ function Get-TargetResource
$maxRetries = 5
$retryIntervalInSeconds = 30
$domainShouldExist = (Test-Path (Get-TrackingFilename -DomainName $DomainName))
do {
do {
try
{
if ($isDomainMember) {
Expand All @@ -121,13 +127,13 @@ function Get-TargetResource
## the domain is already UP - and this resource shouldn't run. Domain controller functionality
## should be checked by the xADDomainController resource?
Write-Verbose ($localizedData.DomainFound -f $domain.DnsRoot);

$targetResource = @{
DomainName = $domain.DnsRoot;
ParentDomainName = $domain.ParentDomain;
DomainNetBIOSName = $domain.NetBIOSName;
}

return $targetResource;
}
catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException]
Expand Down Expand Up @@ -214,9 +220,9 @@ function Test-TargetResource
{
$message = $localizedData.ResourcePropertyValueIncorrect -f 'DomainName', $domainFQDN, $targetResource.DomainName;
Write-Verbose -Message $message;
$isCompliant = $false;
$isCompliant = $false;
}

$propertyNames = @('ParentDomainName','DomainNetBIOSName');
foreach ($propertyName in $propertyNames)
{
Expand All @@ -227,11 +233,11 @@ function Test-TargetResource
{
$message = $localizedData.ResourcePropertyValueIncorrect -f $propertyName, $propertyValue, $targetResource.$propertyName;
Write-Verbose -Message $message;
$isCompliant = $false;
$isCompliant = $false;
}
}
}

if ($isCompliant)
{
Write-Verbose -Message ($localizedData.ResourceInDesiredState -f $domainFQDN);
Expand Down Expand Up @@ -281,13 +287,13 @@ function Set-TargetResource
[ref] $null = $PSBoundParameters.Remove("Debug");
## Not entirely necessary, but run Get-TargetResouece to ensure we raise any pre-flight errors.
$targetResource = Get-TargetResource @PSBoundParameters;

$installADDSParams = @{
SafeModeAdministratorPassword = $SafemodeAdministratorPassword.Password;
NoRebootOnCompletion = $true;
Force = $true;
}

if ($PSBoundParameters.ContainsKey('DnsDelegationCredential'))
{
$installADDSParams['DnsDelegationCredential'] = $DnsDelegationCredential;
Expand All @@ -305,7 +311,7 @@ function Set-TargetResource
{
$installADDSParams['SysvolPath'] = $SysvolPath;
}

if ($PSBoundParameters.ContainsKey('ParentDomainName'))
{
Write-Verbose -Message ($localizedData.CreatingChildDomain -f $DomainName, $ParentDomainName);
Expand All @@ -329,8 +335,8 @@ function Set-TargetResource
$installADDSParams['DomainNetbiosName'] = $DomainNetBIOSName;
}
Install-ADDSForest @installADDSParams;
Write-Verbose -Message ($localizedData.CreatedForest -f $DomainName);
}
Write-Verbose -Message ($localizedData.CreatedForest -f $DomainName);
}

"Finished" | Out-File -FilePath (Get-TrackingFilename -DomainName $DomainName) -Force

Expand All @@ -340,8 +346,4 @@ function Set-TargetResource

} #end function Set-TargetResource

## Import the common AD functions
$adCommonFunctions = Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath '\MSFT_xADCommon\MSFT_xADCommon.ps1';
. $adCommonFunctions;

Export-ModuleMember -Function *-TargetResource;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
# Directory.
#

## Import the common AD functions
$adCommonFunctions = Join-Path `
-Path (Split-Path -Path $PSScriptRoot -Parent) `
-ChildPath '\MSFT_xADCommon\MSFT_xADCommon.psm1'
Import-Module -Name $adCommonFunctions

function Get-TargetResource
{
[OutputType([System.Collections.Hashtable])]
Expand Down Expand Up @@ -217,8 +223,4 @@ function Test-TargetResource

}

## Import the common AD functions
$adCommonFunctions = Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath '\MSFT_xADCommon\MSFT_xADCommon.ps1'
. $adCommonFunctions

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Localized messages
## Import the common AD functions
$adCommonFunctions = Join-Path `
-Path (Split-Path -Path $PSScriptRoot -Parent) `
-ChildPath '\MSFT_xADCommon\MSFT_xADCommon.psm1'
Import-Module -Name $adCommonFunctions

# Localized messages
data localizedData
{
# culture="en-US"
Expand Down Expand Up @@ -34,18 +40,18 @@ function Get-TargetResource
(
[Parameter(Mandatory)]
[System.String] $DomainName,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String] $DomainController,

[Parameter()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.CredentialAttribute()]
$Credential
$Credential
)
Assert-Module -ModuleName 'ActiveDirectory';

$PSBoundParameters['Identity'] = $DomainName;
$getADDefaultDomainPasswordPolicyParams = Get-ADCommonParameters @PSBoundParameters;
Write-Verbose -Message ($localizedData.QueryingDomainPasswordPolicy -f $DomainName);
Expand Down Expand Up @@ -73,42 +79,42 @@ function Test-TargetResource
(
[Parameter(Mandatory)]
[System.String] $DomainName,

[Parameter()]
[System.Boolean] $ComplexityEnabled,

[Parameter()]
[System.UInt32] $LockoutDuration,

[Parameter()]
[System.UInt32] $LockoutObservationWindow,

[Parameter()]
[System.UInt32] $LockoutThreshold,

[Parameter()]
[System.UInt32] $MinPasswordAge,

[Parameter()]
[System.UInt32] $MaxPasswordAge,

[Parameter()]
[System.UInt32] $MinPasswordLength,

[Parameter()]
[System.UInt32] $PasswordHistoryCount,

[Parameter()]
[System.Boolean] $ReversibleEncryptionEnabled,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String] $DomainController,

[Parameter()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.CredentialAttribute()]
$Credential
$Credential
)
$getTargetResourceParams = @{
DomainName = $DomainName;
Expand All @@ -122,7 +128,7 @@ function Test-TargetResource
$getTargetResourceParams['DomainController'] = $DomainController;
}
$targetResource = Get-TargetResource @getTargetResourceParams;

$inDesiredState = $true;
foreach ($property in $mutablePropertyMap)
{
Expand Down Expand Up @@ -159,42 +165,42 @@ function Set-TargetResource
(
[Parameter(Mandatory)]
[System.String] $DomainName,

[Parameter()]
[System.Boolean] $ComplexityEnabled,

[Parameter()]
[System.UInt32] $LockoutDuration,

[Parameter()]
[System.UInt32] $LockoutObservationWindow,

[Parameter()]
[System.UInt32] $LockoutThreshold,

[Parameter()]
[System.UInt32] $MinPasswordAge,

[Parameter()]
[System.UInt32] $MaxPasswordAge,

[Parameter()]
[System.UInt32] $MinPasswordLength,

[Parameter()]
[System.UInt32] $PasswordHistoryCount,

[Parameter()]
[System.Boolean] $ReversibleEncryptionEnabled,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String] $DomainController,

[Parameter()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.CredentialAttribute()]
$Credential
$Credential
)
Assert-Module -ModuleName 'ActiveDirectory';
$PSBoundParameters['Identity'] = $DomainName;
Expand All @@ -219,8 +225,4 @@ function Set-TargetResource
[ref] $null = Set-ADDefaultDomainPasswordPolicy @setADDefaultDomainPasswordPolicyParams;
} #end Set-TargetResource

## Import the common AD functions
$adCommonFunctions = Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath '\MSFT_xADCommon\MSFT_xADCommon.ps1';
. $adCommonFunctions;

Export-ModuleMember -Function *-TargetResource;
8 changes: 5 additions & 3 deletions DSCResources/MSFT_xADGroup/MSFT_xADGroup.psm1
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Import the common AD functions
$adCommonFunctions = Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath '\MSFT_xADCommon\MSFT_xADCommon.ps1'
. $adCommonFunctions
## Import the common AD functions
$adCommonFunctions = Join-Path `
-Path (Split-Path -Path $PSScriptRoot -Parent) `
-ChildPath '\MSFT_xADCommon\MSFT_xADCommon.psm1'
Import-Module -Name $adCommonFunctions

# Localized messages
data LocalizedData
Expand Down
Loading

0 comments on commit 7f7bb4e

Please sign in to comment.