Skip to content

Instantly share code, notes, and snippets.

@Apoc70
Last active October 25, 2021 12:56
Show Gist options
  • Save Apoc70/f6095192646734f59fe3cb7fd1b95328 to your computer and use it in GitHub Desktop.
Save Apoc70/f6095192646734f59fe3cb7fd1b95328 to your computer and use it in GitHub Desktop.
This scripts clears the attribute legacyExchangeDN if set to ADCDisabledMail
# This script clears the legacyExchangeDN attribute of AD objects if the attribute is set to ADCDisabledMail
# Active Directory search base, adjust as needed for your AD
$SearchBase = 'DC=VARUNAGROUP,DC=DE'
# Our search filter
$Filter = 'legacyExchangeDN -eq "ADCDisabledMail"'
$csvFilename = 'ADCDisabledMail-Users.csv'
# Search for user objects matching the filter in the defined search base
$affectedObjects = Get-ADObject -Filter $Filter -SearchBase $SearchBase
# Some output
Write-Host ('{0} object(s) with legacyExchangeDN = ADCDisabledMail found' -f ($affectedObjects | Measure-Object).Count)
# Export users for documentation purposes
if(($affectedObjects | Measure-Object).Count -gt 0) {
$affectedObjects | Export-Csv -Path $csvFilename -Encoding UTF8 -NoTypeInformation -Force
Write-Host ('Object information exported to {0}' -f $csvFilename)
# Clear the attribute
$affectedObjects | Set-ADObject -Clear 'legacyExchangeDN'
Write-Host ('legacyExchangeDN cleared for {0} object(s)' -f ($affectedObjects | Measure-Object).Count)
}
else {
Write-Host 'No user objects found with legacyExchangeDN = ADCDisabledMail'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment