Enable Inheritance for Bulk AD Users (Active Directory)
A PowerShell script to enable inheritance for bulk AD users in an OU, with a safer 2026 version: dry run, ACL backup, AdminSDHolder checks and rollback.
A PowerShell script to remove users from an AD group using a CSV of email addresses, updated for 2026 with dry runs, error handling and an audit log.

When someone hands you a spreadsheet of staff who should no longer be in a security group, clicking through Active Directory Users and Computers is slow and error-prone. In 2022 I wrote a short PowerShell script to remove users from an AD group using a CSV of email addresses, and the approach still works today. Below is the original, followed by the safer version I now recommend.
Group memberships pile up as people change roles, finish projects or leave. HR or a department head usually sends a list of email addresses, not usernames. So the script needs to read each email, find the matching AD account, and remove it from the group.
Two cmdlets in the ActiveDirectory module do the work: Get-ADUser to find the account and Remove-ADGroupMember to remove it. Microsoft still documents Remove-ADGroupMember for Windows Server 2025, so nothing here has been retired or renamed.
email:Get-ADGroupMember -Identity 'GroupName' |
Select-Object Name, SamAccountName, DistinguishedName |
Export-Csv -Path 'C:\Path\to\GroupName-backup.csv' -NoTypeInformation
This is the core idea, with one typo corrected. The published version showed $\_ instead of $_, which stops it running:
Write-Host "Removing users from an AD group."
Import-Csv "Path\to\file\users.csv" | ForEach-Object {
$user = $_.email
$aduserinfo = Get-ADUser -Filter "EmailAddress -eq '$user'"
Remove-ADGroupMember -Identity "GroupName" -Members $aduserinfo -Confirm:$false
Write-Host "User $user successfully removed from the AD group"
}
It reads each row and matches the email (EmailAddress maps to the mail attribute). It then removes the user without prompting.
The original works, but it has gaps I would not accept in production now:
-Confirm:$false removes people silently, with no record of what happened.Here is the version I recommend. It starts in dry-run mode, using -WhatIf behind a simple switch:
#Requires -Modules ActiveDirectory
$GroupName = 'GroupName'
$CsvPath = 'C:\Path\to\users.csv'
$LogPath = "C:\Path\to\removal-log-$(Get-Date -Format yyyyMMdd-HHmmss).csv"
$DryRun = $true # set to $false after checking the dry-run output
$group = Get-ADGroup -Identity $GroupName -ErrorAction Stop
$results = foreach ($row in Import-Csv -Path $CsvPath) {
$email = "$($row.email)".Trim()
if (-not $email) { continue }
$users = @(Get-ADUser -Filter 'mail -eq $email')
if ($users.Count -ne 1) {
[pscustomobject]@{ Email = $email; Status = "Skipped: $($users.Count) matches" }
continue
}
try {
Remove-ADGroupMember -Identity $group -Members $users[0] -Confirm:$false -WhatIf:$DryRun -ErrorAction Stop
$status = if ($DryRun) { 'Would remove' } else { 'Removed' }
[pscustomobject]@{ Email = $email; Status = $status }
}
catch {
[pscustomobject]@{ Email = $email; Status = "Error: $($_.Exception.Message)" }
}
}
$results | Export-Csv -Path $LogPath -NoTypeInformation
$results | Format-Table -AutoSize
The steps to run it:
$GroupName, $CsvPath and $LogPath.$DryRun = $true, -WhatIf shows what would be removed, nothing changes, and the log marks each row "Would remove".mail values that need cleaning.$DryRun = $false and run it again for real.Confirm the users are gone from the group:
$emails = (Import-Csv 'C:\Path\to\users.csv').email
Get-ADGroupMember -Identity 'GroupName' |
Where-Object { $_.objectClass -eq 'user' } |
Get-ADUser -Properties mail |
Where-Object { $emails -contains $_.mail } |
Select-Object Name, mail
No output means nobody from the list remains. Then compare the member count against your backup file to make sure only the intended accounts were removed.
Add-ADGroupMember.If your team would rather hand routine directory work and security reviews to someone else, my company, Standing, provides managed IT and information security services in Iraq and the Kurdistan Region.
The takeaway: the 2022 idea is still sound, but never run a bulk removal blind. Back up the group, dry-run first, act only on exact single matches, and keep the log.
📝 First written from my own work in 2022; updated and expanded in November 2026 with AI assistance, keeping my original fix. Spotted something wrong? Tell me.