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

Posted on 2011-10-31
Last Modified: 2012-05-12
#get list of groups the user belongs to
$GroupNames = Get-QADMemberOf "TestMigration6" -Service "" | Select-Object -ExpandProperty Name

#Move the user via admt from domain to
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
$GroupNames | ForEach-Object { Add-QADGroupMember $_ -Member "user1" -Service "" }

#this step I need to take it a step further to move the users from the groups they were placed in 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
Question by:zanderkid
    LVL 37

    Accepted Solution

    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.
    LVL 37

    Expert Comment

    Sorry yes, you already have Quest

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    A commonly asked question on the site recently has been regarding how do I share the GAL between different forests? I want a list of Contacts representing all the users in a remote domain, How do i get them? It's a problem I was posed with a litt…
    Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now