Skip to content

Commit

Permalink
ADUser: Update the default value logic for CommonName (#460)
Browse files Browse the repository at this point in the history
- Changes to ADUser 
  - Update the logic for setting the default value for the parameter
    `CommonName`. This is due to an how LCM handles parameters when a
    default value is derived from another parameter (issue #427).
  • Loading branch information
johlju authored Aug 3, 2019
1 parent 51a74bc commit 50197b4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
- Now it correctly tests passwords when parameter DomainName is set to
distinguished name and parameter Credential is used ([issue #451](https://github.com/PowerShell/ActiveDirectoryDsc/issues/451)).
- Added integration tests ([issue #359](https://github.com/PowerShell/ActiveDirectoryDsc/issues/359)).
- Update the logic for setting the default value for the parameter
`CommonName`. This is due to an how LCM handles parameters when a
default value is derived from another parameter ([issue #427](https://github.com/PowerShell/ActiveDirectoryDsc/issues/427)).
- Changes to ADDomain
- BREAKING CHANGE: Renamed the parameter `DomainAdministratorCredential`
to `Credential` to better indicate that it is possible to impersonate
Expand Down
33 changes: 30 additions & 3 deletions DSCResources/MSFT_ADUser/MSFT_ADUser.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ function Get-TargetResource
[Parameter()]
[ValidateNotNull()]
[System.String]
$CommonName = $UserName,
$CommonName,

[Parameter()]
[ValidateNotNull()]
Expand Down Expand Up @@ -734,6 +734,15 @@ function Get-TargetResource
$ProxyAddresses
)

<#
This is a workaround to make the resource able to enter debug mode.
For more information see issue https://github.com/PowerShell/ActiveDirectoryDsc/issues/427.
#>
if (-not $PSBoundParameters.ContainsKey('CommonName'))
{
$CommonName = $UserName
}

Assert-Module -ModuleName 'ActiveDirectory'

try
Expand Down Expand Up @@ -1107,7 +1116,7 @@ function Test-TargetResource
[Parameter()]
[ValidateNotNull()]
[System.String]
$CommonName = $UserName,
$CommonName,

[Parameter()]
[ValidateNotNull()]
Expand Down Expand Up @@ -1381,6 +1390,15 @@ function Test-TargetResource
$ProxyAddresses
)

<#
This is a workaround to make the resource able to enter debug mode.
For more information see issue https://github.com/PowerShell/ActiveDirectoryDsc/issues/427.
#>
if (-not $PSBoundParameters.ContainsKey('CommonName'))
{
$CommonName = $UserName
}

Assert-Parameters @PSBoundParameters

$targetResource = Get-TargetResource @PSBoundParameters
Expand Down Expand Up @@ -1723,7 +1741,7 @@ function Set-TargetResource
[Parameter()]
[ValidateNotNull()]
[System.String]
$CommonName = $UserName,
$CommonName,

[Parameter()]
[ValidateNotNull()]
Expand Down Expand Up @@ -1997,6 +2015,15 @@ function Set-TargetResource
$ProxyAddresses
)

<#
This is a workaround to make the resource able to enter debug mode.
For more information see issue https://github.com/PowerShell/ActiveDirectoryDsc/issues/427.
#>
if (-not $PSBoundParameters.ContainsKey('CommonName'))
{
$CommonName = $UserName
}

Assert-Parameters @PSBoundParameters

$targetResource = Get-TargetResource @PSBoundParameters
Expand Down

0 comments on commit 50197b4

Please sign in to comment.