mirror of
https://github.com/EvotecIT/GPOZaurr.git
synced 2026-08-09 18:29:40 +00:00
25 lines
1.2 KiB
PowerShell
25 lines
1.2 KiB
PowerShell
function Remove-GPOZaurrDuplicateObject {
|
|
[cmdletBinding(SupportsShouldProcess)]
|
|
param(
|
|
[int] $LimitProcessing = [int32]::MaxValue,
|
|
[alias('ForestName')][string] $Forest,
|
|
[string[]] $ExcludeDomains,
|
|
[alias('Domain', 'Domains')][string[]] $IncludeDomains,
|
|
[System.Collections.IDictionary] $ExtendedForestInformation
|
|
)
|
|
$getGPOZaurrDuplicateObjectSplat = @{
|
|
Forest = $Forest
|
|
IncludeDomains = $IncludeDomains
|
|
ExcludeDomains = $ExcludeDomains
|
|
ExtendedForestInformation = $ExtendedForestInformation
|
|
}
|
|
|
|
$DuplicateGpoObjects = Get-GPOZaurrDuplicateObject @getGPOZaurrDuplicateObjectSplat
|
|
foreach ($Duplicate in $DuplicateGpoObjects | Select-Object -First $LimitProcessing) {
|
|
try {
|
|
Remove-ADObject -Identity $Duplicate.ObjectGUID -Recursive -ErrorAction Stop -Server $Duplicate.DomainName -Confirm:$false
|
|
} catch {
|
|
Write-Warning "Remove-GPOZaurrDuplicateObject - Deleting $($Duplicate.ConflictDN) / $($Duplicate.DomainName) via GUID: $($Duplicate.ObjectGUID) failed with error: $($_.Exception.Message)"
|
|
}
|
|
}
|
|
} |