Managing Active Directory permissions can sometimes involve giving a user access to a large number of security groups — for example during onboarding, when changing someone’s role, or when granting temporary elevated access.
Doing this manually through Active Directory Users & Computers is time-consuming and error-prone.
PowerShell provides a clean and efficient way to automate the process.
In this post, I’ll show a small and elegant PowerShell script that:
- Retrieves all groups inside a specific OU
- Adds a chosen user as a member of each group
- Outputs both successes and errors, so you know exactly what happened
Import-Module ActiveDirectory
$OU = "OU=Grupper,OU=Company,DC=domain,DC=local"
$User = "debie2dal"
Get-ADGroup -SearchBase $OU -Filter * | ForEach-Object {
try {
Add-ADGroupMember -Identity $_ -Members $User -ErrorAction Stop
Write-Host "OK: Added $User in $($_.Name)"
}
catch {
Write-Host "Error in group $($_.Name): $($_.Exception.Message)"
}
}
When This Script Is Useful
This simple script is extremely helpful in scenarios such as:
- New employee onboarding
Add a full set of role-based permissions in seconds. - Role changes
Assign users to new group structures effortlessly. - Service accounts
Grant access to multiple groups quickly and repeatably. - Environment cleanup
Identify or replicate required group memberships. - Bulk operations
Especially during system migrations or reorganisations.
Final Thoughts
PowerShell is a powerful tool for automating Active Directory tasks — and this small script can save a lot of time when managing group memberships across large environments. It reduces manual effort, eliminates repetitive clicking, and ensures consistent access assignments.
If you need help customizing this script for your organization or extending it with additional capabilities, feel free to reach out.