Script to Move New User to the Identical OU of Existing User
Posted on 2011-05-02
We have several hundred devices that are setup to Auto-login using the same AD account. Because of a software requirement we now need each device to Auto-login with a unique account. We have created the new accounts and I am writing a batch file script to do the move. I have most of the steps I want to automate completed, but I'm having difficulty coming up with a way to move the new accounts to the respective OU of existing accounts.
I can run "dsquery user -samid %ExistingUser%" to get a distiguished name of the existing account but I can't just pipe that over to "dsmove %NewUserDN% -newparent %ExistingUser% since the CN in the existing user's distinguished name is still there.
I guess I'm looking for a way to take the CN= section off of the %ExistingUser% variable to just get the distinguished name of the OU it's in. Unless of course there is an easy way to do this with the ds commands that I'm just overlooking.
Thanks for any suggestions!