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

username1
username2
username3
...

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"

Comments