Skip to content

Commit

Permalink
Changes to xActiveDirectory
Browse files Browse the repository at this point in the history
- Changes to xADComputer
  - Restoring a computer account from the recycle bin no longer fails if
    there are more than one object with the same name in the recycle bin.
    Now it uses the object that was changed last using the property
    whenChanged (issue dsccommunity#271).
- Changes to xADGroup
  - Restoring a group from the recycle bin no longer fails if there are
    more than one object with the same name in the recycle bin. Now it
    uses the object that was changed last using the property whenChanged
    (issue dsccommunity#271).
- Changes to xADOrganizationalUnit
  - Restoring a organization unit from the recycle bin no longer fails if
    there are more than one object with the same name in the recycle bin.
    Now it uses the object that was changed last using the property whenChanged
    (issue dsccommunity#271).
- Changes to xADUser
  - Restoring a user from the recycle bin no longer fails if there are
    more than one object with the same name in the recycle bin. Now it
    uses the object that was changed last using the property whenChanged
    (issue dsccommunity#271).
  • Loading branch information
johlju committed May 11, 2019
1 parent 720a543 commit 7b50612
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@
- Updated unit tests to latest unit test template and refactored the
tests for the function 'Set-TargetResource'.
- Improved test code coverage.
- Changes to xADComputer
- Restoring a computer account from the recycle bin no longer fails if
there are more than one object with the same name in the recycle bin.
Now it uses the object that was changed last using the property
`whenChanged` ([issue #271](https://github.com/PowerShell/xActiveDirectory/issues/271)).
- Changes to xADGroup
- Restoring a group from the recycle bin no longer fails if there are
more than one object with the same name in the recycle bin. Now it
uses the object that was changed last using the property `whenChanged`
([issue #271](https://github.com/PowerShell/xActiveDirectory/issues/271)).
- Changes to xADOrganizationalUnit
- Restoring a organization unit from the recycle bin no longer fails if
there are more than one object with the same name in the recycle bin.
Now it uses the object that was changed last using the property `whenChanged`
([issue #271](https://github.com/PowerShell/xActiveDirectory/issues/271)).
- Changes to xADUser
- Restoring a user from the recycle bin no longer fails if there are
more than one object with the same name in the recycle bin. Now it
uses the object that was changed last using the property `whenChanged`
([issue #271](https://github.com/PowerShell/xActiveDirectory/issues/271)).

## 2.25.0.0

Expand Down
13 changes: 9 additions & 4 deletions DSCResources/MSFT_xADCommon/MSFT_xADCommon.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ function Restore-ADCommonObject
)

$restoreFilter = 'msDS-LastKnownRDN -eq "{0}" -and objectClass -eq "{1}" -and isDeleted -eq $true' -f $Identity, $ObjectClass
Write-Verbose -Message ($localizedString.FindInRecycleBin -f $restoreFilter)
Write-Verbose -Message ($localizedString.FindInRecycleBin -f $restoreFilter) -Verbose

<#
Using IsDeleted and IncludeDeletedObjects will mean that the cmdlet does not throw
Expand All @@ -772,13 +772,18 @@ function Restore-ADCommonObject
$getAdObjectParams.Remove('Identity')
$getAdObjectParams['Filter'] = $restoreFilter
$getAdObjectParams['IncludeDeletedObjects'] = $true
$getAdObjectParams['Properties'] = @('whenChanged')

# If more than one object is returned, we pick the one that was changed last.
$restorableObject = Get-ADObject @getAdObjectParams |
Sort-Object -Descending -Property 'whenChanged' |
Select-Object -First 1

$restorableObject = Get-ADObject @getAdObjectParams
$restoredObject = $null

if ($restorableObject)
{
Write-Verbose -Message ($localizedString.FoundRestoreTargetInRecycleBin -f $Identity, $ObjectClass, $restorableObject.DistinguishedName)
Write-Verbose -Message ($localizedString.FoundRestoreTargetInRecycleBin -f $Identity, $ObjectClass, $restorableObject.DistinguishedName) -Verbose

try
{
Expand All @@ -787,7 +792,7 @@ function Restore-ADCommonObject
$restoreParams['ErrorAction'] = 'Stop'
$restoreParams['Identity'] = $restorableObject.DistinguishedName
$restoredObject = Restore-ADObject @restoreParams
Write-Verbose -Message ($localizedString.RecycleBinRestoreSuccessful -f $Identity, $ObjectClass)
Write-Verbose -Message ($localizedString.RecycleBinRestoreSuccessful -f $Identity, $ObjectClass) -Verbose
}
catch [Microsoft.ActiveDirectory.Management.ADException]
{
Expand Down

0 comments on commit 7b50612

Please sign in to comment.