Sunday, August 9, 2015

Active Directory Moving Users to Another OU via CSV File.

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)


Gokul G said...

Nice blog of server rentals.

Larry Smith said...

This is really a very informational blog post. Your opinion about is really very useful as user point of view. Please keep sharing some more information.

Business Grade VoIP | IT Consultant

Monika Rajput said...

This Article is very better.Our Company provide services throught Virtual No., Tollfree No.,VPS and Bulk Email Server.

Faizan Afzal said... business and personal webpages from united states.

Elizabeth J. Neal said...

Just wanted to thank you from TSC and intorduce these reliable movers moving company in Toronto, Highly recommend hiring them. They were informative on process, timing, very courteous, and exercised care with with our possessions... and above all very patient with the questions that came their way.

advmovers said...

Best Moving Company +971 50 3605353
Office and staff relocation should run as professionally and cost efficiently as any successful business. Therefore ADV MOVERS Corporate aim to provide you with the best moving services and moves without any comebacks.

Movers in Dubai
office movers in dubai
Affordable Moving Company in Dubai
Packer in Dubai
Re locate services in Dubai
Professional Movers in Dubai
Movers and Packers Abu Dhabi

Jessica Schweizer said...

I am glad you take pride in what you write. This makes you stand way out from many other writers that push poorly written content. los angeles mover