Wednesday, January 8, 2014

MS Active Directory - Move multiple users to a new OU using commandline

This is a pretty handy technique to move a bunch of users to a new OU in Active Directory using command line:

1. Create a list of usernames, each username per line: users.txt


2. In the AD Domain Controller, open command prompt and enter this command:

for /f %i in (users.txt) do dsquery user -samid %i | dsmove -newparent "OU=New OU,DC=Mydomain,DC=COM"