How to move OU members into other OU based on sAMaccountname or other attribute

Eaven HUANG 2,156 Reputation points
2021-07-01T07:48:35.137+00:00

Dear friend,

We have an OU containing around 1000+ members and we will need to create sub-OU to separate them. We will create 10 sub-OUs and move them into different ones. I have an excel list containing the members' E-mail, sAMAccountName, can we do this in bulk based on their E-mail field or sAMAccountName attribute?

Many thanks in advance for any assistance.

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,637 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 34,271 Reputation points Microsoft Vendor
    2021-07-01T09:15:32.097+00:00

    Hi,

    You can create a script to do this. The Move-ADObject cmdlet moves an AD object to a specific container.

    $sAMAccountName = "someuser"  
    $ou = "OU=test,DC=contoso,DC=com"  
    Get-ADUser -Identity $sAMAccountName | Move-ADObject -TargetPath $ou  
    

    https://learn.microsoft.com/en-us/powershell/module/activedirectory/move-adobject

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful