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.