Powershell script to migrate user from one domain to another then move them to a new group on the new domain

#get list of groups the user belongs to
$GroupNames = Get-QADMemberOf "TestMigration6" -Service "microsoft1.contoso.com" | Select-Object -ExpandProperty Name

#Move the user via admt from domain microsoft1.contoso.com to microsoft2.contoso.com
admt user /N "user1" /IF:YES /MGS:NO /SD: "microsoft1" /TD: "microsoft2" /TO:"test users" /UUR:YES /PO:Complex /FGM:YES

#add user to the groups in microsoft2.contoso.com
$GroupNames | ForEach-Object { Add-QADGroupMember $_ -Member "user1" -Service "microsoft2.contoso.com" }

#this step I need to take it a step further to move the users from the groups they were placed in microsoft2.contoso.com and move them to a group with the same name only GBL_FLS_ is now in front of the name. the example is using dsget but I would like to continue with powershell.
dsgetgroup "$GroupNames" -members | dsmod group "GBL_FLS_$GroupNames
Who is Participating?
Neil RussellTechnical Development LeadCommented:
You could download and use the Quest ad commandlets. I often work with multiple domains in one script using that.

You have the  -service "my.domain.local:389" command switch that allows you to direct each command to a different domain server.

You could do something like...

$D1Users = get-qadgroupmember "Groupname" -service "my.domain.local:389"

foreach ($user in $D1Users) {
$UserName = $user.Displayname
add-qadgroupmember "GBL_FLS_Groupname" $username -service "myOther.domain.local:389"

You would need to be logged in with an account that had domain admin in BOTH domains.
Neil RussellTechnical Development LeadCommented:
Sorry yes, you already have Quest
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.