We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Powershell Script to Move users from one OU to Another

gd6627
gd6627 asked
on
Medium Priority
5,794 Views
Last Modified: 2012-05-11
I need a powershell script that takes input from a CSV of user samaccount names and moves them from one ou to another .
Comment
Watch Question

Here is a starting point:
http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/f7cd1004-2f23-4ce6-b090-d5679df5610c

You might also consider using PowerGUI with the AD powerpack:  http://www.powergui.org/index.jspa

Good luck!
mug

Author

Commented:
I have power gui and i loaded quest cmdlts need to put it together is where am getting stuck
You could use import-csv:
note: if you don't have a header row, use something like: Import-Csv .\test.csv -header ("col1","col2","username")
note: this script assumes you have a "username" column specified in the header

Import-Csv c:\scripts\users.csv | foreach {
 
# Finding the location of the user account Andre:
$Root = [ADSI]''

$searcher = new-object System.DirectoryServices.DirectorySearcher($root)
$searcher.filter = "(&(objectClass=user)(DisplayName= $_.username))"
$User = $searcher.findone()

# Binding the user account to $AUser and the OU to move to to $MovetoOU
$ADSPath = $User.Properties.adspath
$MoveToOU = [ADSI]("LDAP://OU=NewOU,DC=mydomain,DC=com")
$AUser = [ADSI]("$ADSPath")

# Command to Do the actual move
$AUser.PSBase.moveto($MoveToOU)

}
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
thank you
Any luck with this?

Author

Commented:
yes that worked
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.