skip to Main Content

Bulk move AD users to another OU with PowerShell

You already learned how to bulk convert user mailbox to shared mailbox. This time we like to bulk move AD objects to a new OU (Organizational Unit). There are more than a hundred of shared mailboxes across Active Directory (AD). If we search for the shared mailboxes in AD and move them to the OU, it takes time. This is an excellent way to automate the task with PowerShell. In this article, you will learn how to bulk move AD users with PowerShell to another OU from CSV file.

Before you start to bulk move AD users

If you have a list of AD users in one OU, you can select the AD objects and move them in Active Directory Users and Computers. Yes, it’s that simple to drag and drop. What if you have users in different OUs? In our case, there are over a hundred shared mailboxes. It will take a lot of time to search and move them. That’s why we have to work smart and make use of PowerShell.

Create a target OU in Active Directory

Create a target OU if you don’t have one. We recommend to keep it tidy and move all the shared mailboxes to the target OU SharedMailbox.

Bulk move AD users to another OU with PowerShell target empty

Get the distinguished name

You can get the OU distinguished name in Active Directory. Right-click the target OU and click Properties. Go to the Attribute Editor tab. Find the attribute distuingedName in the attributes list. Double-click to open the string and copy the value. You will need it in the next part.

Bulk move AD users to another OU with PowerShell OU Distinguished Name

You can also get the Organizational Unit distinguished name with PowerShell.

Create CSV file with AD users

Before we can run the script, we need to have a CSV file with the AD users SamAccountName. In our example, the shared mailboxes are going to be moved. When you create a mailbox, an AD object is automatically created in AD.

Bulk move AD users to another OU with PowerShell source

Run Exchange Management Shell as administrator. The first cmdlet will give us the result. The second cmdlet will export the result to a CSV file.

After exporting the CSV file, the next step is to read the CSV file content with PowerShell.

Check the content in CSV file

Verify that the CSV file is readable in PowerShell.

Bulk move AD users to another OU PowerShell script

Download the Move-ADUsers.ps1 PowerShell script or copy and paste the below code in Notepad. Give it the name Move-AdUsers.ps1 and place it in the C:\scripts folder. Create a scripts folder if you don’t have one.

  • Line 5: Edit the CSV file name and the path.
  • Line 8: Edit the target OU.

In the next step, we will have a look at the bulk move AD Users PowerShell script.

Bulk move AD users to another OU with CSV file

Run the PowerShell script to bulk move AD users to another OU. Good to know is that there is a -WhatIf parameter added to the script. If you run the script, nothing will happen in the environment. You will get an output showing what will happen.

Everything is looking good. We can remove the -WhatIf parameter and rerun the PowerShell script.

Verify the result

Have a look at Active Directory Users and Computers. The shared mailboxes in the CSV file are moved to another OU. In this case, the SharedMailbox OU.

Bulk move AD users to another OU with PowerShell target

Another check, but this time with PowerShell.

Everything is looking great. Did this help you to bulk move AD objects to another OU?

Read more: Create bulk mailboxes in Exchange 2016 with PowerShell »


In this article, you learned how to bulk move AD users to another OU with PowerShell. Download the Move-ADusers.ps1 PowerShell script, edit the CSV path, and the target OU. Run the script and verify that the AD objects are moved successfully to the new OU.

Did you enjoy this article? You may also like Change Users UPN with Powershell. Don’t forget to follow us and share this article.



ALI TAJRAN is a passionate IT Architect, IT Consultant, and Microsoft Certified Trainer. He started Information Technology at a very young age, and his goal is to teach and inspire others. Read more »

This Post Has 0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top