MsExchange Blog Spot Telnet25

August 9, 2015

Active Directory Moving Users to Another OU via CSV File.

Filed under: General — telnet25 @ 10:36 pm

In this task we will move AD users location from their current OU into different OU.

  • we will need to prepare CSV file contains all AD users ( names ) you wish to move into another OU ( Organizational Unit ) see the sample below. Name the first column as “name” and list all the account underneath.
  • Save this into a location on your server where you will be running the PS script from, for instance  C:\temp\Acc_MoveList.csv



This is the location where we will move all the accounts into


# Import AD Module
import-module ActiveDirectory

# Import CSV
$MoveList = Import-Csv -Path "C:\Temp\Acc_MoveList.csv"
# Specify target OU.This is where users will be moved.
$TargetOU =  "OU=SVC_Users,OU=VA,DC=TekPros,DC=com"
# Import the data from CSV file and assign it to variable
$Imported_csv = Import-Csv -Path "C:\temp\Acc_MoveList.csv"

$Imported_csv | ForEach-Object {
     # Retrieve DN of User.
     $UserDN  = (Get-ADUser -Identity $_.Name).distinguishedName
     Write-Host " Moving Accounts ….. "
     # Move user to target OU.
     Move-ADObject  -Identity $UserDN  -TargetPath $TargetOU
Write-Host " Completed move "
$total = ($MoveList).count
Write-Host "Accounts have been moved succesfully…"

Few things you will need to change to run the PS,

  • $TargetOU =  "OU=SVC_Users,OU=VA,DC=TekPros,DC=com" ( you will need to change this to make sure it fits into your environment
  • $MoveList = Import-Csv -Path "C:\Temp\Acc_MoveList.csv" (you will need to change this to make sure it fits into your environment)

Once you make the changes you should be able to move the users listed on your CSV file with no issues.


Download the script and sample CSV from here

you can also download the script from  here

Oz Casey, Dedeal  ( MVP North America)
Security+, Project +, Server + (Blog) (Blog)


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: