Announcement

Collapse
No announcement yet.

Moving computers from OU

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

  • Moving computers from OU

    Hi

    I have a txt file with a list of computers
    i wouldl like the easyest way to move all the computers to another OU (lets say Disable OU)

    how can i do it ???

    thanks

  • #2
    Re: Moving computers from OU

    The command is DSMOVE
    e.g (to move a user).
    dsmove "cn=Conn, Steve,ou=IT,dc=contoso,dc=com" –newparent
    ou=Training,dc=contoso,dc=com
    You would need to either modify your file so each line is similar to the above, or pipe the list of computers into a batch file with the DSMOVE command. Rems or one of the other scripting guru's will have an elegant solution for you

    Reference http://www.microsoft.com/technet/tec...s/default.aspx
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      Re: Moving computers from OU

      Thanks

      who is Rems ??

      Comment


      • #4
        Re: Moving computers from OU

        Hi

        This is the line that i worte , but nothing happens ?
        dsmove "cn=DANB,ou=Disabled,ou=computers,ou=XXX,ou=XX,ou= regions,dc=net,dc=XX,dc=XX,dc=com" –newparent
        ou=computers,ou=xxx,ou=XXX,ou=regions,dc=net,dc=pl m,dc=eds,dc=com
        i tried to move DANB computer to the Computer OU


        thx

        Comment


        • #5
          Re: Moving computers from OU

          Here u go......

          http://www.microsoft.com/technet/scr...6/hey0623.mspx

          Regards,
          Kapil Sharma
          ~~~~~~~~~~~~~
          Life is too short, Enjoy It.

          Comment


          • #6
            Re: Moving computers from OU

            Originally posted by tulik23 View Post
            Thanks

            who is Rems ??
            Rems is a Scripting Guru (and Guru is such an inadequate word to use when describing his talent), a man who causes the ground to rumble with respect when he walks across it. If Rems can't write, modify or find a script for what you want done, then it isn't possible to script it.

            Hope that helps with your question. To view his work, read through the Scripting Forum and be totally impressed with what he has posted. I for one am envy at what he can do.


            Why is he not a Scripting MVP?
            .
            .
            1 1 was a racehorse.
            2 2 was 1 2.
            1 1 1 1 race 1 day,
            2 2 1 1 2

            Comment


            • #7
              Re: Moving computers from OU

              Originally posted by biggles77 View Post
              Rems is a Scripting Guru (and Guru is such an inadequate word to use when describing his talent), a man who causes the ground to rumble with respect when he walks across it.
              To clarify the above:
              If you have five dollars and Rems has five dollars, Rems has more money than you.

              There is no 'ctrl' button on Rems's computer. Rems is always in control.

              Apple pays Rems 99 cents every time he listens to a song.

              Rems can sneeze with his eyes open.

              Rems can eat just one Lay's potato chip.

              Rems is suing Myspace for taking the name of what he calls everything around you.

              Rems destroyed the periodic table, because he only recognizes the element of surprise.

              Rems can kill two stones with one bird.

              When the Boogeyman goes to sleep every night, he checks his closet for Rems.

              Rems doesn't read books. He stares them down until he gets the information he wants.

              There is no theory of evolution. Just a list of creatures Rems has allowed to live.

              Outer space exists because it's afraid to be on the same planet with Rems.

              Rems does not sleep. He waits.

              Rems is the reason why Waldo is hiding.

              Rems counted to infinity - twice.

              There is no chin behind Rems’ beard. There is only another fist.

              When Rems does a pushup, he isn’t lifting himself up, he’s pushing the Earth down.

              Rems is so fast, he can run around the world and punch himself in the back of the head.

              Rems’ hand is the only hand that can beat a Royal Flush.

              Rems can lead a horse to water AND make it drink.

              Rems doesn’t wear a watch, HE decides what time it is.

              Rems can slam a revolving door.

              Rems does not get frostbite. Rems bites frost
              Tom Jones
              MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
              PhD, MSc, FIAP, MIITT
              IT Trainer / Consultant
              Ossian Ltd
              Scotland

              ** Remember to give credit where credit is due and leave reputation points where appropriate **

              Comment


              • #8
                Re: Moving computers from OU

                >>Apple pays Rems 99 cents every time he listens to a song.

                That's why my macbook Pro was that expensive
                Marcel
                Technical Consultant
                Netherlands
                http://www.phetios.com
                http://blog.nessus.nl

                MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
                "No matter how secure, there is always the human factor."

                "Enjoy life today, tomorrow may never come."
                "If you're going through hell, keep going. ~Winston Churchill"

                Comment


                • #9
                  Re: Moving computers from OU

                  Hey, Can someone make this thread sticky?





                  EDIT
                  --------------------------------------------------
                  Today it is my birthday, and I'm thinking of printing one of Tom's statements on my T-shirt
                  I think I will choose all )

                  Originally posted by Chris View Post
                  Why is he not a Scripting MVP?
                  Well, I would loose the MVM here.
                  And, comparing to the real masters in scripting, I still have to learn a whole lada lot.

                  That brings me an idea for a final statement on my T-Shirt;
                  "Despide all the above, Rems stays modest, he didn't give himself the 'Rems award'".

                  To Marcel,
                  "sorry for that man"
                  Last edited by Rems; 23rd January 2008, 13:45.

                  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


                  • #10
                    Re: Moving computers from OU

                    ON topic;

                    tulik23, you mensiond a 'list of computers' in a *.txt file,
                    in what format do you have the list?
                    - is each computer written on a new line, or did you use separators?
                    - do you have in the list the computer's netbiosNames, Accountnames (domain\comp) or the DistinguishedName of the computer object?

                    If your list have the computer netbiosnames on each line, you can simply use a batch (or even a on-line commandline from a prompt).
                    The important thing to keep in mind here is, if using the samid, that the sAMAccountName of each computer_object always has a $ sign attached to it in the AD!
                    (In this batch this $-sign will statically be added to each computer name from your text file, so you don't have to worry about that)
                    Code:
                    @echo off
                    
                    For /f "usebackq" %%! In ("c:\computers.txt") Do (
                     (dsquery computer -samid "%%!$")|(
                     dsmove -newparent "OU=Sales Computers,DC=domain,DC=local"
                     ))
                    The batch is using DSMOVE.exe to move the computerobject to the newparent, it loops through a list of computernames.

                    If your list is a mixure of all formats for the computername, then use a *.vbs script.
                    The link of kapilsharma11 shows an example how to query the AD database for the 'name attrribute' of the computer objects. You can use this code in a Loop that is going through the lines of the text file. (note on line 5 in the MS scriptingGuy sample the SET statement is missing!)
                    The sample is fine if you search for only a few computers. And, it would be better to narrow the search down to provide a starting OU. With this method every object will be connected and the attribute examend.
                    - The processing methods used by this script are in fact the same as what the batch is doing:
                    1. The batch also starting with a query (dsquery.exe) for each computername on the list individualy, to retrieve it's distinguished name (DN) in the AD domain.
                      (When using the LDAP provider, the distinguished name is used to map to the unique location of the object (the ADsPath) in the AD)
                    2. Directly when it is found, the object is moved (dsmove.exe) to the new parent (=distinguished name of the OU). The ADsPath of the object is changed.


                    Below is a script that accepts all 3 formats for the computername in the txt file (every computers must be on a new line). This script use 'Name translation' instead of using a 'search string' to retrieve the computer's DN .

                    Code:
                    Option Explicit
                    
                    ' Global Constants for the NameTranslate object.
                    Const ADS_NAME_INITTYPE_GC = 3  '<--(requires clear access to the Global Catalog!)
                    Const ADS_NAME_TYPE_NT4    = 3
                    Const ADS_NAME_TYPE_1779   = 1
                    
                    Dim strInputFile, strOU
                    
                    ' Input = list of computer names or dn
                    strInputFile = "c:\computers.txt"
                    
                    ' Distinguished Name of the Destination OU
                    strOU = "OU=Sales Computers,DC=domain,DC=local"
                    
                    
                    Dim objFSO, objTSIn
                    Dim WshNetwork
                    Dim sCurrNbDomain, strComputer, strComputerDN
                    Dim oDestOU, objComputer
                    
                    Set WshNetwork = WScript.CreateObject("WScript.Network")
                     sCurrNbDomain = WshNetwork.UserDomain
                    Set oDestOU = GetObject("LDAP://" & strOU )
                    Set objFSO = CreateObject("Scripting.FileSystemObject")
                    
                    ' Open Input File
                    Set objTSIn = objFSO.OpenTextFile(strInputFile)
                    
                    Do Until objTSIn.AtEndOfStream  '<----[loop through list of computernames]
                      strComputer = objTSIn.ReadLine
                      If Not (InStr(strComputer, "=")<>0) Then
                        If Not (InStr(strComputer, "\")<>0) Then _
                             strComputer = sCurrNbDomain & "\" & strComputer
                           strComputerDN = FindComputer(strComputer)
                      Else strComputerDN = strComputer
                      End If
                      If Not IsEmpty(strComputerDN) Then
                        ' Bind to the computer object in Active Directory with the LDAP provider.
                        Set objComputer = GetObject("LDAP://" & strComputerDN)
                    
                        ' Move the computer object to the OU
                        oDestOU.MoveHere objComputer.adspath, vbNullString
                      End If
                    Loop
                    
                    objTSIn.Close '<---[close Input File] 
                    
                    wscript.quit
                    
                    
                    Function FindComputer(nbCompAccName)
                      ' http://www.rlmueller.net/NameTranslateFAQ.htm !!!
                      ' http://msdn2.microsoft.com/en-us/library/aa772194(VS.85).aspx
                      Dim objTrans
                      FindComputer = Empty
                      On Error Resume Next
                    
                      ' Use the NameTranslate object to convert the NT computer name to the
                      ' Distinguished Name required for the LDAP provider.
                      Set objTrans = CreateObject("NameTranslate")
                    
                      ' Initialize NameTranslate by locating the Global Catalog.
                      objTrans.Init ADS_NAME_INITTYPE_GC, ""
                    
                      ' Use the Set method to specify the NT format of the object name.
                      objTrans.Set ADS_NAME_TYPE_NT4, nbCompAccName & "$"  '<-- the $-sign is added to match the 'sAMAccountName'
                    
                      If Not (err<>0) then
                        ' Use the Get method to retrieve the RPC 1779 Distinguished Name.
                        FindComputer = objTrans.Get(ADS_NAME_TYPE_1779)
                      Else Err.clear
                      End If
                    End Function
                    \Rems
                    Last edited by Rems; 24th January 2008, 23:21. Reason: the previous script was for testing, changed it! now it will realy MOVE the objects!

                    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