[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Powershell Script to Move users from one OU to Another

Posted on 2011-04-25
7
Medium Priority
?
4,430 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 .
0
Comment
Question by:gd6627
7 Comments
 
LVL 6

Expert Comment

by:Kris Montgomery
ID: 35462923
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
0
 

Author Comment

by:gd6627
ID: 35463029
I have power gui and i loaded quest cmdlts need to put it together is where am getting stuck
0
 
LVL 16

Expert Comment

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

}
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 35

Accepted Solution

by:
YZlat earned 2000 total points
ID: 35469224
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
0
 

Author Comment

by:gd6627
ID: 36133711
thank you
0
 
LVL 16

Expert Comment

by:Bryan Butler
ID: 36318099
Any luck with this?
0
 

Author Comment

by:gd6627
ID: 36334765
yes that worked
0

Featured Post

New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

834 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