Monday, 8 August 2016

Move Multiple AD computer objects to different OUs

Move multiple Computer objects to different Organization Units

Request in-detail

Today, I had received request from team to Move around 100s of computer objects to different OUs in my domain. 

The information which I received was in Excel sheet but you know they are not in order. 

Solution:

So, I spent few minutes to sort them in order first also the OU path was received in Canonical Name not the exact LDAP path. 

First extracted OU names from the Canonical names provided and queried in AD to get the exact LDAP path. Then I prepared the sheet like below input file information.


Sample CSV Input file ( Save the file as comps.csv )






Simple Powershell script was prepared to do this move JOB. Script does not have any error checking but powershell console throw error message when object not found. 

Input file should be shared in the same directory where the powershell script will be saved. 


# Script Content:  # Don't copy this line.

Import-Module activedirectory

$Inputs=Import-csv ".\comps.csv"

foreach ( $line in $Inputs )

{

Get-adcomputer $($line.ID) | Move-ADObject -TargetPath $($line.dn)

}

1 comment:

  1. Excellent post Murugan, keep posted us with new article.

    Thanks

    ReplyDelete