Announcement

Collapse
No announcement yet.

send/pipe results to dsmove.exe

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

  • send/pipe results to dsmove.exe

    I have been trying to move a list of computer to a new OU with the following command

    Code:
    for /F "Tokens=1" %1 in (computer.txt) do dsmove %1 -newparent "OU=45Day,OU=Computers,OU=aa,DC=aa,DC=bb,DC=cc,DC=dddd,DC=ss"
    I receive the error;

    dsmove failed:Value for 'Target object for this command' has incorrect format.

    any help would be great.
    Last edited by Rems; 15th April 2011, 19:57.

  • #2
    Re: dsmove script from a list

    Originally posted by hodester View Post
    I have been trying to move a list of computer to a new OU with the following command

    Code:
    for /F "Tokens=1" %1 in (computer.txt) do dsmove %1 -newparent "OU=45Day,OU=Computers,OU=aa,DC=aa,DC=bb,DC=cc,DC=dddd,DC=ss"
    I receive the error;

    dsmove failed:Value for 'Target object for this command' has incorrect format.

    any help would be great.
    Hi,

    Firstly you cannot use "%1" in a for-do loop as the variable. Try %a (or %%a if it is used in a batch). %a is case sensitive!

    What computer names are in the txt-file, it should be the computer's distinguished name.

    Instead of "Tokens=1" use "Tokens=*"
    And you should put quotes around "%a" in dsmove "%a" -newparent "....."

    Does the real target for "OU=45Day,OU=Computers,OU=aa,DC=aa,DC=bb,DC=cc,DC=d ddd,DC=ss" contain perhaps any special characters/signs that needs to be escaped?


    /Rems
    Last edited by Rems; 15th April 2011, 20:22.

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: dsmove script from a list

      I have updated the command as suggested and I receive this error,


      for /F "Token=*" %a in (test.txt) do dsmove "%a" -newparent OU=45Day,OU=Computers,OU=aa,DC=aa,DC=bb,DC=cc,DC=d ddd,DC=ss
      Token=*" was unexpected at this time.

      If I remove the "Token=*" the command works. I received the original error because my test file didn't have distinguished name.


      This move doesn't have any special characters in the OU's but I do have some OUs with spaces in the name.

      Comment


      • #4
        Re: dsmove script from a list

        On a similar note I have been asked to run the command on a daily/weekly basis. Will this command do it?

        for /F %a in ('dsquery computer -limit 1000 "OU=Computers,OU=aa,DC=aa,DC=bb,DC=cc,DC=dddd,DC=s s" -stalepwd 45') do dsmove "%a" -newparent OU=45Day,OU=Computers,OU=aa,DC=aa,DC=bb,DC=cc,DC=d ddd,DC=ss

        Thanks for the help.

        Comment


        • #5
          Re: dsmove script from a list

          Originally posted by hodester View Post
          I have updated the command as suggested and I receive this error,


          for /F "Token=*" %a in (test.txt) do dsmove "%a" -newparent OU=45Day,OU=Computers,OU=aa,DC=aa,DC=bb,DC=cc,DC=d ddd,DC=ss
          Token=*" was unexpected at this time.

          If I remove the "Token=*" the command works. I received the original error because my test file didn't have distinguished name.


          This move doesn't have any special characters in the OU's but I do have some OUs with spaces in the name.
          Try "tokens=*"

          This posting is provided "AS IS" with no warranties, and confers no rights.

          __________________

          ** Remember to give credit where credit's due **
          and leave Reputation Points for meaningful posts

          Comment


          • #6
            Re: dsmove script from a list

            Originally posted by hodester View Post
            On a similar note I have been asked to run the command on a daily/weekly basis. Will this command do it?

            for /F %a in ('dsquery computer -limit 1000 "OU=Computers,OU=aa,DC=aa,DC=bb,DC=cc,DC=dddd,DC=s s" -stalepwd 45') do dsmove "%a" -newparent OU=45Day,OU=Computers,OU=aa,DC=aa,DC=bb,DC=cc,DC=d ddd,DC=ss

            Thanks for the help.
            Without the For-Do, just,
            Code:
            dsquery computer -limit 1000 "OU=Computers,OU=aa,DC=aa,DC=bb,DC=cc,DC=dddd,DC=ss" -stalepwd 45 | dsmove -newparent OU=45Day,OU=Computers,OU=aa,DC=aa,DC=bb,DC=cc,DC=dddd,DC=ss

            Or, check out OldCmp.exe
            OldCmp Usage: http://www.joeware.net/freetools/tools/oldcmp/usage.htm (the switches -move, -newparent, -age, -unsafe and -forreal)

            /Rems

            This posting is provided "AS IS" with no warranties, and confers no rights.

            __________________

            ** Remember to give credit where credit's due **
            and leave Reputation Points for meaningful posts

            Comment


            • #7
              Re: dsmove script from a list

              Thank you for the information. The script is working great.

              Today I was asked if it is possible to filter out some OU's and I have found I can pipe a dsquery into findstar /vic:"ou=" and that will remove the OU from the query. Is it possible to take the filtered results and send/pipe it to the dsmove command.

              I have looked at the OldCmp.exe I do not see a way to filter out OU's.
              It is a great tool, thank you for the link.

              Thank you for your time.

              If this should be a separate thread, please let me know.
              Last edited by hodester; 19th April 2011, 22:16. Reason: additional information

              Comment


              • #8
                Re: dsmove script from a list

                Originally posted by hodester View Post
                Today I was asked if it is possible to filter out some OU's and I have found I can pipe a dsquery into findstar /vic:"ou=" and that will remove the OU from the query.
                Yes you can use one findstr.exe /v statement to filter-out multiple OUs like,
                Code:
                findstr.exe /viC:",OU=Test Objects1,......." /viC:",OU=Test Objects2,......." /viC:",OU=Test Objects3,......."
                note, you may need to pass the RDN of the container/OU to the findstr "filter string" instead of just the OU name, an OU name might not be unique in an AD domain.



                Is it possible to take the filtered results and send/pipe it to the dsmove command.
                Pipe DSQuery results to DsMove is for some reason limited to just one computer. For moving multiple computers you can do this:
                Code:
                for /f "tokens=*" %* in ('dsquery.exe computer -limit 1000 "OU=aa,DC=aa,DC=bb,DC=cc,DC=dddd,DC=ss" ^|findstr /vic:",OU=Test Objects1,"') Do dsmove.exe %* -newparent "OU=45Day,OU=Computers,OU=aa,DC=aa,DC=bb,DC=cc,DC=dddd,DC=ss"
                OR, you can use AdMod.exe instead of DsMove.exe for moving the objects:
                Code:
                dsquery.exe computer -limit 0 "OU=aa,DC=aa,DC=bb,DC=cc,DC=dddd,DC=ss" |findstr /ic:",OU=Test Objects1," |AdMod.exe -safety 1000 -move "OU=45Day,OU=Computers,OU=aa,DC=aa,DC=bb,DC=cc,DC=dddd,DC=ss"

                /Rems



                If this should be a separate thread, please let me know.
                Not necessary, I'll change the subject title for this thread.

                _
                Last edited by Rems; 20th April 2011, 12:25.

                This posting is provided "AS IS" with no warranties, and confers no rights.

                __________________

                ** Remember to give credit where credit's due **
                and leave Reputation Points for meaningful posts

                Comment

                Working...
                X