Powershell Script to Move users from one OU to Another

Posted on 2011-04-25
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 .
Question by:gd6627
    LVL 6

    Expert Comment

    by:Kris Montgomery
    Here is a starting point:

    You might also consider using PowerGUI with the AD powerpack:

    Good luck!

    Author Comment

    I have power gui and i loaded quest cmdlts need to put it together is where am getting stuck
    LVL 16

    Expert Comment

    by:Bryan Butler
    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

    LVL 35

    Accepted Solution

    try something like that

    $Allusers = import-csv -path c:\mycsvfile.csv 
    $ou = "OU=Test,DC=YourDomain,DC=com"
    foreach ($user in $Allusers) {
    	Move-QADObject $user -To $ou

    Open in new window

    But first add this snap-in: Quest.ActiveRoles.ADManagement

    Author Comment

    thank you
    LVL 16

    Expert Comment

    by:Bryan Butler
    Any luck with this?

    Author Comment

    yes that worked

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    Suggested Solutions

    I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
    Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now