Copy User’s Groups to Another User

Applies to Active Directory, User Management
Modules needed: ActiveDirectory

This is a very useful script if you find yourself needing to add a user to all the groups another user is a part of. Typically, you could just copy the user in Active Directory to make the new user. But in this case, I was asked to do this for an existing user. There’s no simple way to do this within Active Directory, but this quick script gets it done.

The script asks for the user needing to be added, and the user to copy the groups from.

Import-Module ActiveDirectory
$creds = (Get-Credential)
$addedUser = Read-Host ("User to add to groups")
$copiedUser = Read-Host ("User to copy groups from")
Write-Host "Working on it..." -ForegroundColor Yellow
Get-ADUser -identity $copiedUser -Properties memberof | Select-Object -ExpandProperty memberof | Add-ADGroupMember -Members $addedUser -Credential $creds -Passthru | Format-Table -Property Name,GroupCategory,GroupScope,DistinguishedName -AutoSize

At the end of the script, the groups the user was added to are shown.


Add User to Distribution Group

Applies to Exchange, and O365.
Modules needed: Exchange, or Microsoft.Exchange.Management.ExoPowershellModule

This is a simple script that just asks for input on adding members to a distribution group. The reason I made this script was because I wanted to simplify this process for non-admin IT folks, and enter multiple users at a time.

To add multiple users, separate them with commas.
Example: Members: druggeri,tdanza,pporter

$dl = Read-Host "Distribution Group"
get-distributiongroup -identity $dl
$members = Read-Host "Members"
$members = $members.split(',')
foreach ($m in $members) {
  Add-DistributionGroupMember -identity $dl -member $m }
Write-Host "Confirmation:" -ForegroundColor Green
get-distributiongroupmember -identity $dl | Format-Table -AutoSize

At the end of the script, a confirmation is shown using get-distributiongroupmember on the entered group. This is just so you can verify your change applied, and that the correct users were added.