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

image

image

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

image

# 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
$total
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.

image

Download the script and sample CSV from here

http://1drv.ms/1IXThhx

you can also download the script from  here

https://gallery.technet.microsoft.com/scriptcenter/Move-AD-users-into-target-4322d774

Oz Casey, Dedeal  ( MVP North America)
MCITP (EMA), MCITP (SA)
MCSE , M+, S+, MCDST
Security+, Project +, Server +

http://telnet25.wordpress.com/ (Blog)
http://smtp25.blogspot.com/ (Blog)

https://twitter.com/message_talk

7 comments:

Unknown said...

Nice blog of server rentals.

Unknown 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

Anonymous said...

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

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

Elizabeth J. Neal said...

Wow, this is really interesting reading. I am glad I found this and got to read it. Great job on this content. I like it. movers venice

Ana Hicks said...

Great articles and great layout. Your blog post deserves all of the positive feedback it’s been getting. very good moving services

Furniture Movers Oklahoma City said...

Very thoughtful bblog