Skip to content

Commit

Permalink
Merge pull request #100 from PlagueHO/Feature-84/Add-ODJ-Support-To-x…
Browse files Browse the repository at this point in the history
…ADComputer

Add ODJ Support to xADComputer - Fixes #84
  • Loading branch information
TravisEz13 authored Jul 2, 2016
2 parents 9d75bf7 + 5ab03d2 commit 3cce7fc
Show file tree
Hide file tree
Showing 16 changed files with 1,383 additions and 1,223 deletions.
8 changes: 4 additions & 4 deletions Assert-HADC.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
param ()

# A configuration to Create High Availability Domain Controller
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingComputerNameHardcoded', '')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
param()

# A configuration to Create High Availability Domain Controller
$secpasswd = ConvertTo-SecureString "Adrumble@6" -AsPlainText -Force
$domainCred = New-Object System.Management.Automation.PSCredential ("sva-dscdom\Administrator", $secpasswd)
$safemodeAdministratorCred = New-Object System.Management.Automation.PSCredential ("sva-dscdom\Administrator", $secpasswd)
Expand Down
5 changes: 3 additions & 2 deletions Assert-ParentChildDomains.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
param ()
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingComputerNameHardcoded', '')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
param()

$secpasswd = ConvertTo-SecureString "Adrumble@6" -AsPlainText -Force
$domainCred = New-Object System.Management.Automation.PSCredential ("sva-dscdom\Administrator", $secpasswd)
Expand Down
78 changes: 44 additions & 34 deletions DSCResources/MSFT_xADCommon/MSFT_xADCommon.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data localizedString
MembersIsEmptyError = The Members parameter is empty. At least one group member must be provided.
IncludeAndExcludeConflictError = The member '{0}' is included in both '{1}' and '{2}' parameter values. The same member must not be included in both '{1}' and '{2}' parameter values.
IncludeAndExcludeAreEmptyError = The '{0}' and '{1}' parameters are either both null or empty. At least one member must be specified in one of these parameters.
CheckingMembers = Checking for '{0}' members.
MembershipCountMismatch = Membership count is not correct. Expected '{0}' members, actual '{1}' members.
MemberNotInDesiredState = Member '{0}' is not in the desired state.
Expand Down Expand Up @@ -42,18 +42,28 @@ function Test-DomainMember {
[CmdletBinding()]
[OutputType([System.Boolean])]
param ( )
$isDomainMember = [System.Boolean] (Get-CimInstance -ClassName Win32_ComputerSystem -Verbose:$false).PartOfDomain;
$isDomainMember = [System.Boolean] (Get-CimInstance -ClassName Win32_ComputerSystem -Verbose:$false).PartOfDomain;
return $isDomainMember;
}


# Internal function to get the domain name of the computer
function Get-DomainName {
[CmdletBinding()]
[OutputType([System.String])]
param ( )
$domainName = [System.String] (Get-CimInstance -ClassName Win32_ComputerSystem -Verbose:$false).Domain;
return $domainName;
} # function Get-DomainName

# Internal function to build domain FQDN
function Resolve-DomainFQDN {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[OutputType([System.String])]
[System.String] $DomainName,

[Parameter()] [AllowNull()]
[System.String] $ParentDomainName
)
Expand Down Expand Up @@ -102,7 +112,7 @@ function Get-ADObjectParentDN
Redistribution and use in source and binary forms, with or without modification, are permitted provided that
the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
Expand All @@ -128,7 +138,7 @@ function Get-ADObjectParentDN
[System.String]
$DN
)

# https://www.uvm.edu/~gcd/2012/07/listing-parent-of-ad-object-in-powershell/
$distinguishedNameParts = $DN -split '(?<![\\]),';
$distinguishedNameParts[1..$($distinguishedNameParts.Count-1)] -join ',';
Expand All @@ -145,15 +155,15 @@ function Assert-MemberParameters
[ValidateNotNull()]
[System.String[]]
$Members,

[ValidateNotNull()]
[System.String[]]
$MembersToInclude,

[ValidateNotNull()]
[System.String[]]
$MembersToExclude,

[ValidateNotNullOrEmpty()]
[System.String]
$ModuleName = 'xActiveDirectory'
Expand Down Expand Up @@ -207,7 +217,7 @@ function Assert-MemberParameters
}
}
}

} #end function Assert-MemberParameters

## Internal function to remove duplicate strings (members) from a string array
Expand Down Expand Up @@ -265,17 +275,17 @@ function Test-Members
[AllowNull()]
[System.String[]]
$ExistingMembers,

## Explicit array members
[AllowNull()]
[System.String[]]
$Members,

## Compulsory array members
[AllowNull()]
[System.String[]]
$MembersToInclude,

## Excluded array members
[AllowNull()]
[System.String[]]
Expand All @@ -286,7 +296,7 @@ function Test-Members
{
if ($null -eq $Members)
{
$Members = @();
$Members = @();
}
Write-Verbose ($localizedString.CheckingMembers -f 'Explicit');
$Members = [System.String[]] @(Remove-DuplicateMembers -Members $Members);
Expand All @@ -307,10 +317,10 @@ function Test-Members
} #end if $Members

if ($PSBoundParameters.ContainsKey('MembersToInclude'))
{
{
if ($null -eq $MembersToInclude)
{
$MembersToInclude = @();
$MembersToInclude = @();
}
Write-Verbose -Message ($localizedString.CheckingMembers -f 'Included');
$MembersToInclude = [System.String[]] @(Remove-DuplicateMembers -Members $MembersToInclude);
Expand All @@ -329,7 +339,7 @@ function Test-Members
{
if ($null -eq $MembersToExclude)
{
$MembersToExclude = @();
$MembersToExclude = @();
}
Write-Verbose -Message ($localizedString.CheckingMembers -f 'Excluded');
$MembersToExclude = [System.String[]] @(Remove-DuplicateMembers -Members $MembersToExclude);
Expand Down Expand Up @@ -358,7 +368,7 @@ function ConvertTo-TimeSpan
[ValidateNotNullOrEmpty()]
[System.UInt32]
$TimeSpan,

[Parameter(Mandatory)]
[ValidateSet('Seconds','Minutes','Hours','Days')]
[System.String]
Expand All @@ -384,8 +394,8 @@ function ConvertTo-TimeSpan
Convert timespan into the total number of seconds, minutes, hours or days.
.EXAMPLE
$Get-ADDefaultDomainPasswordPolicy
ConvertFrom-TimeSpan
ConvertFrom-TimeSpan
#>
function ConvertFrom-TimeSpan
{
Expand All @@ -397,7 +407,7 @@ function ConvertFrom-TimeSpan
[ValidateNotNullOrEmpty()]
[System.TimeSpan]
$TimeSpan,

[Parameter(Mandatory)]
[ValidateSet('Seconds','Minutes','Hours','Days')]
[System.String]
Expand All @@ -415,22 +425,22 @@ function ConvertFrom-TimeSpan
<#
.SYNOPSIS
Returns common AD cmdlet connection parameter for splatting
.PARAMETER CommonName
.PARAMETER CommonName
When specified, a CommonName overrides theUsed by the xADUser cmdletReturns the Identity as the Name key. For example, the Get-ADUser, Set-ADUser and
Remove-ADUser cmdlets take an Identity parameter, but the New-ADUser cmdlet uses the
Name parameter.
.PARAMETER UseNameParameter
.PARAMETER UseNameParameter
Returns the Identity as the Name key. For example, the Get-ADUser, Set-ADUser and
Remove-ADUser cmdlets take an Identity parameter, but the New-ADUser cmdlet uses the
Name parameter.
.EXAMPLE
$getADUserParams = Get-CommonADParameters @PSBoundParameters
Returns connection parameters suitable for Get-ADUser using the splatted cmdlet
parameters.
.EXAMPLE
$newADUserParams = Get-CommonADParameters @PSBoundParameters -UseNameParameter
Returns connection parameters suitable for New-ADUser using the splatted cmdlet
parameters.
#>
Expand All @@ -445,38 +455,38 @@ function Get-ADCommonParameters
[Alias('UserName','GroupName','ComputerName')]
[System.String]
$Identity,

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

[Parameter()]
[ValidateNotNull()]
[Alias('DomainAdministratorCredential')]
[System.Management.Automation.PSCredential]
[System.Management.Automation.CredentialAttribute()]
$Credential,

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

[Parameter()]
[System.Management.Automation.SwitchParameter]
$UseNameParameter,

[Parameter()]
[System.Management.Automation.SwitchParameter]
$PreferCommonName,

## Catch all to enable splatted $PSBoundParameters
[Parameter(ValueFromRemainingArguments)]
$RemainingArguments
)

if ($UseNameParameter)
{
if ($PreferCommonName -and ($PSBoundParameters.ContainsKey('CommonName')))
Expand All @@ -497,17 +507,17 @@ function Get-ADCommonParameters
$adConnectionParameters = @{ Identity = $Identity; }
}
}

if ($Credential)
{
$adConnectionParameters['Credential'] = $Credential;
}

if ($Server)
{
$adConnectionParameters['Server'] = $Server;
}

return $adConnectionParameters;
} #end function Get-ADCommonParameters

Expand Down
Loading

0 comments on commit 3cce7fc

Please sign in to comment.