diff --git a/CHANGELOG.md b/CHANGELOG.md index b003c1e34..a0d8a8cfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md) - Fixed ability to clear `ServicePrincipalNameSuffix` and `UserPrincipalNameSuffix` ([issue #548](https://github.com/PowerShell/ActiveDirectoryDsc/issues/548)). - ADObjectPermissionEntry - Fixed issue where Get-DscConfiguration / Test-DscConfiguration throw an exception when target object path does not yet exist ([issue #552](https://github.com/dsccommunity/ActiveDirectoryDsc/issues/552)) +- ADOrganizationalUnit + - Fixed issue where Get-DscConfiguration / Test-DscConfiguration throw an exception when parent path does not yet exist ([issue #553](https://github.com/dsccommunity/ActiveDirectoryDsc/issues/553)) ### Changed diff --git a/Tests/Unit/MSFT_ADOrganizationalUnit.Tests.ps1 b/Tests/Unit/MSFT_ADOrganizationalUnit.Tests.ps1 index bfa8c70cc..eff74aeef 100644 --- a/Tests/Unit/MSFT_ADOrganizationalUnit.Tests.ps1 +++ b/Tests/Unit/MSFT_ADOrganizationalUnit.Tests.ps1 @@ -114,15 +114,15 @@ try $targetResource.Description | Should -BeNullOrEmpty } - It 'Should throw the correct error if the path does not exist' { + It 'Returns "Ensure" = "Absent" when OU parent path does not exist and does not throw an exception' { Mock -CommandName Assert-Module Mock -CommandName Get-ADOrganizationalUnit -MockWith { throw New-Object Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException } - $errorMessage = $script:localizedData.PathNotFoundError -f $testPresentParams.Path - { Get-TargetResource -Name $testPresentParams.Name -Path $testPresentParams.Path } | Should -Throw $errorMessage + $targetResource = Get-TargetResource -Name $testPresentParams.Name -Path $testPresentParams.Path + $targetResource.Ensure | Should -Be 'Absent' } - It 'Should throw the correct error if an unkwon error occurs' { + It 'Should throw the correct error if an unknown error occurs' { $error = 'Unknown Error' Mock -CommandName Assert-Module Mock -CommandName Get-ADOrganizationalUnit -MockWith { throw $error } diff --git a/source/DSCResources/MSFT_ADOrganizationalUnit/MSFT_ADOrganizationalUnit.psm1 b/source/DSCResources/MSFT_ADOrganizationalUnit/MSFT_ADOrganizationalUnit.psm1 index fac251dbc..e21b3d6f8 100644 --- a/source/DSCResources/MSFT_ADOrganizationalUnit/MSFT_ADOrganizationalUnit.psm1 +++ b/source/DSCResources/MSFT_ADOrganizationalUnit/MSFT_ADOrganizationalUnit.psm1 @@ -43,8 +43,7 @@ function Get-TargetResource } catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] { - $errorMessage = $script:localizedData.PathNotFoundError -f $Path - New-ObjectNotFoundException -Message $errorMessage + Write-Verbose -Message ($script:localizedData.OUPathIsAbsent -f $Path) } catch { diff --git a/source/DSCResources/MSFT_ADOrganizationalUnit/en-US/MSFT_ADOrganizationalUnit.strings.psd1 b/source/DSCResources/MSFT_ADOrganizationalUnit/en-US/MSFT_ADOrganizationalUnit.strings.psd1 index 0b9e8ad85..e66e43d15 100644 --- a/source/DSCResources/MSFT_ADOrganizationalUnit/en-US/MSFT_ADOrganizationalUnit.strings.psd1 +++ b/source/DSCResources/MSFT_ADOrganizationalUnit/en-US/MSFT_ADOrganizationalUnit.strings.psd1 @@ -10,5 +10,5 @@ ConvertFrom-StringData @' OUExistsButShouldNot = OU '{0}' exists when it should not exist. (ADOU0008) OUDoesNotExistButShould = OU '{0}' does not exist when it should exist. (ADOU0009) OUDoesNotExistAndShouldNot = OU '{0}' does not exist and is in the desired state. (ADOU0010) - PathNotFoundError = The Path '{0}' was not found. (ADOU0011) + OUPathIsAbsent = The OU Path '{0}' is absent from Active Directory. (ADOU0011) '@