Announcement

Collapse
No announcement yet.

Script to move users into an OU...

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script to move users into an OU...

    Hey guys, I'm hoping someone can help me with problem...

    I have inherited quite a few Domain Controllers running 2000 Server and 2003 Server, however, when the users have been created they have all been placed into the standard users folder. What I want is to write a script that will move these users into an OU depending on the groups they are a member of... i.e. everyone that is a member of the "Marketing" group needs moving into the "Marketing" OU

    Is this possible? If so does anyone have any existing scripts or pointers??

    Any help is greatly appreciated.

    Rob.
    Rob.
    ----
    There are 10 types of people in the world: Those who understand binary, and those who don't...

  • #2
    How would you deal with situation when a used is member of more than one group that is representing a target OU ?
    i.e.: user is member of Marketing AND Managers.

    If this is not the case, you can do it with dsquery/dsmove:

    Code:
    C:\>dsquery * -filter "&(objectcategory=person)(objectclass=user)(memberof=CN=helpdesk,OU=groups,OU=accounts,DC=antid0t,DC=net)" -limit 0 | dsmove  -newparent "OU=mailboxes,OU=accounts,DC=antid0t,DC=net"
    dsmove succeeded:CN=support,OU=Users,OU=Accounts,DC=antid0t,DC=net
    How many groups like this do you have ?
    Last edited by guyt; 2nd September 2006, 19:00.
    Guy Teverovsky
    "Smith & Wesson - the original point and click interface"

    Comment


    • #3
      There are 7 or so groups... I am in the fortunate position that I can guarantee no user will be in 2 target groups!

      Thanks for the info, I will have a look at this!

      Rob.
      Rob.
      ----
      There are 10 types of people in the world: Those who understand binary, and those who don't...

      Comment


      • #4
        I got round to trying dsquery and dsmove this week and they worked like a dream! Thanks for the tip!

        Rob.
        Rob.
        ----
        There are 10 types of people in the world: Those who understand binary, and those who don't...

        Comment


        • #5
          Hi,

          I have used this script once with success, however I have come accross a small problem - It works when there is 1 user to move, however if there are any more than 1 dsmove just errors and doesn't move any accounts...

          Code:
          C:\>dsquery * -filter "&(objectcategory=person)(objectclass=user)(memberof=CN=te
          st,OU=accounts,DC=CSSTEST,DC=local)" -limit 0
          "CN=Test1,OU=accounts,DC=CSSTEST,DC=local"
          "CN=Test2,OU=accounts,DC=CSSTEST,DC=local"
          
          C:\>dsquery * -filter "&(objectcategory=person)(objectclass=user)(memberof=CN=te
          st,OU=accounts,DC=CSSTEST,DC=local)" -limit 0 | dsmove -newparent "OU=Test,DC=CS
          STEST,DC=local"
          dsmove failed:`CN=Test2,OU=accounts,DC=CSSTEST,DC=local' is an unknown parameter
          .
          type dsmove /? for help.
          This is the error I recieve, as you can see there are 2 accounts in AD that are a member of the group, however it will not move them, if I was to take 1 user out of the group it would work like a dream!

          Does anyone have any ideas they would be willing to share?

          Thanks in advance!

          Rob.
          Last edited by guyt; 2nd September 2006, 19:00.
          Rob.
          ----
          There are 10 types of people in the world: Those who understand binary, and those who don't...

          Comment


          • #6
            stupid limitation... here is the workaround:
            Code:
            For /F "delims=*" %i in ('dsquery * -filter "(&(objectcategory=person)(objectclass=user)(memberof=CN=test,OU=accounts,DC=CSSTEST,DC=local))"') do dsmove -newparent "OU=Test,DC=CS STEST,DC=local" %i
            Last edited by guyt; 2nd September 2006, 18:59.
            Guy Teverovsky
            "Smith & Wesson - the original point and click interface"

            Comment


            • #7
              Thanks for the info Guy and your promt response... I will give it a whirl tomorrow!

              Rob.
              Rob.
              ----
              There are 10 types of people in the world: Those who understand binary, and those who don't...

              Comment


              • #8
                Re: Script to move users into an OU...

                i got some help.
                I need to however to use something like

                dsquery user -desc "Student ID:* User creadted for gard of 2007 during there *" |do dsmove -newparent "OU=07,OU=Students,OU=Users,"

                to move users will simplar descriptions to a Single OU.
                Could you help me I am trying to debug:

                For /F "delims=user" %i in ('dsquery user -desc "Student ID:* User creadted for gard of 2007 during there *" -limit 0') do dsmove -newparent "OU=07,OU=Students,OU=Users,OU=Restricted,DC=bsd,D C=brewster,DC=wednet,DC=edu" %i

                Thanks much

                Comment


                • #9
                  Re: Script to move users into an OU...

                  AH I got it all figured out
                  Code:
                  For /F "delims=*" %%u IN ('dsquery user -desc *2007*') DO dsmove %%u -newparent OU=07,OU=Students,OU=Users,OU=Restricted,DC=bsd,DC=brewster,DC=wednet,DC=edu
                  Worked for me palced in bat file and added one for each year (2008,2009,etc)
                  Your guys post really help for giving me some ideas but what is & thing

                  Comment


                  • #10
                    Re: Script to move users into an OU...

                    Originally posted by Geekbsd
                    Your guys post really help for giving me some ideas but what is & thing
                    Ohhh ! Those are remains of migration from different forums software. the "&" should be "&" - logical AND in the LDAP filter. I have just fixed the code in the thread
                    Last edited by guyt; 2nd September 2006, 19:01.
                    Guy Teverovsky
                    "Smith & Wesson - the original point and click interface"

                    Comment

                    Working...
                    X