Sunday, August 9, 2015

Move Ad Computer Accounts from csv File into Target OU.

In this example we will move selected computer accounts from csv file into target OU. You will need to prepare csv file similar the one below and name the first column “CN”  and save it to server where you will be running the script from.This script will be very handy if you need to move computers from different locations into selected target OU.

You will need to change few things within the script to make it work within your environment.

$TargetOU = 'OU=Computers,OU=VA,DC=TekPros,DC=com'  (Change this to make sure it suits your needs)

 

image

Here is the script

#################################################################
# This script will help to move bulk ad computer accounts into target OU
# Written 08/08/15 Casey, Dedeal
# Fell free to change use any part of this script
#
http://www.smtp25.blogspot.com/
#################################################################

#Importing AD Module
Write-Host " Importing AD Module..... "
import-module ActiveDirectory
Write-Host " Importing Move List..... "
# Reading list of computers from csv and loading into variable
$MoveList = Import-Csv -Path "C:\Temp\PC_Move_List.csv"
# defining Target Path
$TargetOU = 'OU=Computers,OU=VA,DC=TekPros,DC=com'
$countPC    = ($movelist).count
Write-Host " Starting import computers ..."

foreach ($Computer in $MoveList){   
    Write-Host " Moving Computer Accounts..."
    Get-ADComputer $Computer.CN | Move-ADObject -TargetPath $TargetOU
}

Write-Host " Completed Move List "

Write-Host " $countPC  Computers has been moved "

You can download the script from this link

https://gallery.technet.microsoft.com/scriptcenter/Move-AD-Computer-Object-4ed2c5f8

http://1drv.ms/1L07yMU

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

2 comments:

Anonymous said...

I have around 2000 computers in the computer container and I need to move 700 computers to a different OU. I have the list of computers in a CSV file.. I was able to use your powershell script that can search AD and move the computers. However, I may have some computers in the list that are in different OU and I do not want them moved to the target OU. The script is search the whole AD and moving computers if the name matches, regardless the OU..
I am a newbie in powershell, so any help will be greatly appreciated.

furniture movers Dubai said...

Dubai furniture movers’ administrations in UAE situated here to help you with moving furniture and flats affirming incredible guidelines. Our point is to make furniture moving a simpler errand like finishing a vase. The primary thought process is to move furniture without taking any pressure. furniture movers Dubai your heap as the best moving organization in Dubai. Regardless of whether you are moving over the road or state we take all your strain and uneasiness in our shoulders and give you the best help to movement.