Copy group membership from user to user

by southtx07 at 2013-04-03 15:53:26

My script is not copying group memberships over and I cant figure out what I’m doing wrong. Please help. There are over 100 accounts with different memberships. So basically oldacctA membership will go to newacctA, oldacctB to newacctB, etc.

$OldUser = Get-Content -Path c:\powershell\olduser.txt | Get-QADUser
$NewUser = Get-Content -Path c:\powershell\newuser_adm.txt | Get-QADUser

$users = Get-QADUser $OldUser | select memberof
foreach($user in $users.memberof)
{
Add-QADGroupMember -Identity $user -Member $NewUser
}
by Matt Hitchcock at 2013-04-03 23:07:11
What errors are you getting from your script currently? Are you connecting to ActiveRoles or running against a native AD? What is the content of your text files?

At first glance, I would probably try:

$OldUser = Get-QADUser (Get-Content -Path c:\powershell\olduser.txt)
$NewUser = Get-QADUser (Get-Content -Path c:\powershell\newuser_adm.txt)

foreach ($group in $OldUser.Memberof)
{
Add-QADGroupMember -Identity $group -Member $NewUser
}