From 50197b4ab73b30f6b50b72cba656c7bb18e61154 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sat, 3 Aug 2019 11:09:00 +0200 Subject: [PATCH] ADUser: Update the default value logic for CommonName (#460) - 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). --- CHANGELOG.md | 3 +++ DSCResources/MSFT_ADUser/MSFT_ADUser.psm1 | 33 ++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d54167546..68fcffa2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/DSCResources/MSFT_ADUser/MSFT_ADUser.psm1 b/DSCResources/MSFT_ADUser/MSFT_ADUser.psm1 index 6a9817a60..d6fc72061 100644 --- a/DSCResources/MSFT_ADUser/MSFT_ADUser.psm1 +++ b/DSCResources/MSFT_ADUser/MSFT_ADUser.psm1 @@ -460,7 +460,7 @@ function Get-TargetResource [Parameter()] [ValidateNotNull()] [System.String] - $CommonName = $UserName, + $CommonName, [Parameter()] [ValidateNotNull()] @@ -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 @@ -1107,7 +1116,7 @@ function Test-TargetResource [Parameter()] [ValidateNotNull()] [System.String] - $CommonName = $UserName, + $CommonName, [Parameter()] [ValidateNotNull()] @@ -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 @@ -1723,7 +1741,7 @@ function Set-TargetResource [Parameter()] [ValidateNotNull()] [System.String] - $CommonName = $UserName, + $CommonName, [Parameter()] [ValidateNotNull()] @@ -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