Web Images News Groups Scholar Blogs Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
help needed moving mulitple computer accounts
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Rob  
View profile  
 More options Jan 5 2007, 1:13 pm
Newsgroups: microsoft.public.scripting.vbscript
From: Rob <R...@discussions.microsoft.com>
Date: Fri, 5 Jan 2007 05:13:01 -0800
Local: Fri, Jan 5 2007 1:13 pm
Subject: help needed moving mulitple computer accounts
Hi,
first off let me say I'm a total novice and am looking for a decent book -
any recommendations?  I'm considering the following:
1) AD Cookbook - Robbie ALlen
2) AD 3rd Ed - Joe Richards
3) AD - Robbie Allen/ Alistair Lowe-Norris
May not be the right newsgroup for this tho..

So, to my question...
I am trying to script moving multiple computer accounts from unknown OU's to
a  known OU within one domain in AD.
I have created a list of these computers that I want to move.  
I have found a script in the script centre:

On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

objOU = GetObject("LDAP://ou=Redundant Objects,ou=Redundant Computer
Objects,dc=domain,dc=com")

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
    "SELECT ADsPath FROM 'LDAP://dc=domain,dc=com' WHERE
objectCategory='computer' " & _
        "AND Name='computenamer'"
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst

Do Until objRecordSet.EOF
    strADsPath = objRecordSet.Fields("ADsPath").Value
    objOU.MoveHere strADsPath, vbNullString
    objRecordSet.MoveNext
Loop

>>finish

http://www.microsoft.com/technet/scriptcenter/resources/qanda/jun06/h...
(I've changed computername and domainname)
Now this is supposed to move a comp account from an unknown OU to known OU
however I tested this with one computer account and it didn't work.

I then found this post which details writing a batch file and using an input
file:

1 input.txt

computer_name_1
computer:name_2

2 the batch file

@echo off

echo ****************************************
Echo * script to move computers*
echo ****************************************

for /F %%1 in (input.txt) do (
cscript move_cmp.vbs %%1 //B //Nologo >> err_log.txt 2>>&1 )

3 the VBS move_cmp.vbs FILE

dim nomepc
ParseCommandLine()

Const ADS_PROPERTY_APPEND = 3
Set objRootDSE = GetObject("LDAP://rootDSE")

'************************************************************************** ***
'* INTO STRVARIABL LINE PUT THE PATH WHERE THE object will be moved
'* (EX: strVariabl = ",OU=Standard Users,OU=DomainNAME,")
'************************************************************************** ***
'************************************************************************** ***
strVariabl = "OU=Public Desktops,OU=PIPPO,OU=PIPPO"
'************************************************************************** ***
'************************************************************************** ***
'************************************************************************** ***
strFissa = strVariabl & "," & objRootDSE.Get("defaultNamingContext")
wscript.echo strFissa

Set objNewOU = GetObject("LDAP://"& strFissa)
Set objMoveComputer = objNewOU.MoveHere _
("LDAP://CN="& nomepc & ",CN=Computers," &
objRootDSE.Get("defaultNamingContext"), "CN=" &nomepc)

Sub ParseCommandLine()
Dim vArgs

set vArgs = WScript.Arguments

if vArgs.Count <> 1 then
DisplayUsage()
Else
nomepc = vArgs(0)
End if
End Sub

I've not changed any of the variables here but this script only looks in the
computers container and not throught the entire AD structure.
Ideally I would like either the first script to use a lookup file or the 2nd
script to search the entire AD but my knowledge does not extend that far.
I'd be very grateful for any help.
Thanks


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Mueller  
View profile  
 More options Jan 5 2007, 2:00 pm
Newsgroups: microsoft.public.scripting.vbscript
From: "Richard Mueller" <rlmueller-NOS...@ameritech.NOSPAM.net>
Date: Fri, 5 Jan 2007 08:00:06 -0600
Local: Fri, Jan 5 2007 2:00 pm
Subject: Re: help needed moving mulitple computer accounts
If you want to know how AD works I have Joe Richards' book and like it. If
you want to learn how to script administrative tasks I'd recommend "Micrsoft
Windows 2000 Scripting Guide - Automating System Administration". I have the
book, but it's also available online at:

http://www.microsoft.com/resources/documentation/windows/2000/server/...

A quick look at your script and it seems OK, but definitely remove the "On
Error Resume Next" statement. It is not needed and makes the script ignore
all errors. This makes troubleshooting impossible. If you run the script
without this statement and get an error message, you have something to fix.

I assume you have a text file with the NetBIOS names of computers. I would
use NameTranslate rather than ADO for this, as it seems more efficient. I
have used code similar to below:
===================
Option Explicit

Dim strFile, strTargetOU, objFSO, objFile, objOU
Dim objRootDSE, strDNSDomain, objTrans, strNetBIOSDomain
Dim strComputer, strComputerDN, objComputer

Const ADS_NAME_INITTYPE_DOMAIN = 1
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1179 = 1

' Specify text file of computer NetBIOS names.
strFile = "c:\scripts\Computers.txt"

' Specify target OU to move computer objects into.
strTargetOU = "Detention,ou=West,dc=MyDomain,dc=com"

' Open the file for read access.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, 1)

' Bind to the target OU.
Set objOU = GetObject("LDAP://" & strTargetOU)

' Determine DNS domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")

' Use the NameTranslate object to find the NetBIOS domain name from
' the DNS domain name.
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_TYPE_NT4, strDNSDomain
objTrans.Set ADS_NAME_TYPE_1179, strDNSDomain
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
' Remove trailing backslash.
strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)

' Use the NameTranslate object to convert computer NetBIOS
' names to Distinguished Names.
objTrans.Init ADS_NAME_INITTYPE_DOMAIN, strNetBIOSDomain

' Read lines from the file.
Do Until objFile.AtEndOfStream
    strComputer = Trim(objFile.ReadLine)
    If (strComputer <> "") Then
        ' Convert NetBIOS name to DN.
        ' NetBIOS name must have "$" appended to end.
        ' Trap error if computer not found.
        On Error Resume Next
        objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain _
            & "\" & strComputer & "$"
        If (Err.Number <> 0) Then
            On Error GoTo0
            Wscript.Echo "Computer not found: " & strComputer
        Else
            On Error GoTo 0
            strComputerDN = objTrans.Get(ADS_NAME_TYPE_1179)
            ' Bind to the computer object.
            Set objComputer = GetObject("LDAP://" & strComputerDN)
            ' Move the computer object to the target OU.
            objTargetOU.MoveHere objComputer.AdsPath, vbNullString
        End If
    End If
Loop

Wscript.Echo "Done"
=============
You need only modify the file name and the Distinguished Name of the target
OU. This script figures out the domain. Notice also that I bind to the
computer object, so I know I get the correct AdsPath. Sometimes this makes a
difference. I believe NameTranslate is more efficient than ADO.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

"Rob" <R...@discussions.microsoft.com> wrote in message

news:819002EE-8D00-4AA5-AA91-7BF569B58CA9@microsoft.com...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rob  
View profile  
 More options Jan 5 2007, 3:30 pm
Newsgroups: microsoft.public.scripting.vbscript
From: Rob <R...@discussions.microsoft.com>
Date: Fri, 5 Jan 2007 07:30:00 -0800
Subject: Re: help needed moving mulitple computer accounts
Richard,
You are a diamond - that worked a treat.
The tip of removing the "on error resume next" was great  by itself as I
could see where things were failing- for starters I had the path of the OU
slightly jumbled...
Also managed to fix a couple of errors in the script you gave me:

line 52 needed a space: On Error GoTo 0
line 60 needed to change objTargetOU to objOU as was giving an error saying
objTargetOU wasn't defined (which of course it wasn't)

Thanks also for the recommendations re books, now just need to find an extra
few hours in the day!
Cheers
Rob


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Mueller  
View profile  
 More options Jan 5 2007, 6:03 pm
Newsgroups: microsoft.public.scripting.vbscript
From: "Richard Mueller" <rlmueller-NOS...@ameritech.NOSPAM.net>
Date: Fri, 5 Jan 2007 12:03:41 -0600
Local: Fri, Jan 5 2007 6:03 pm
Subject: Re: help needed moving mulitple computer accounts
Nice work catching the errors. I put that together too fast.

Richard

"Rob" <R...@discussions.microsoft.com> wrote in message

news:3A26881B-09BC-4ED2-AE08-9A3F7CE24C87@microsoft.com...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
lee  
View profile  
 More options Jun 13 2008, 2:41 am
Newsgroups: microsoft.public.scripting.vbscript
From: lee <l...@discussions.microsoft.com>
Date: Thu, 12 Jun 2008 19:41:01 -0700
Local: Fri, Jun 13 2008 2:41 am
Subject: Re: help needed moving mulitple computer accounts
Richard this is a great script and saved my butt last weekend.

      I need to run it on about 1000 pc's next week and would like to get a
text output of the machines as it goes through the list of pc's. (I thought I
could add that part myself but haven't been successful.)
Any quick and efficient ideas?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ThatsIT.net.au  
View profile  
 More options Jun 13 2008, 3:41 pm
Newsgroups: microsoft.public.scripting.vbscript
From: "ThatsIT.net.au" <me@work>
Date: Fri, 13 Jun 2008 23:41:36 +0800
Local: Fri, Jun 13 2008 3:41 pm
Subject: Re: help needed moving mulitple computer accounts
this will loop though all the computers in active directory

Const ADS_SCOPE_SUBTREE = 2
dim fso:Set fso = CreateObject("Scripting.FileSystemObject")
Set results = fso.CreateTextFile("computers.txt", True)
dim objRootDSE:Set objRootDSE = GetObject("LDAP://rootDSE")
dim strDomain:strDomain = "LDAP://" & objRootDSE.Get("defaultNamingContext")
Set oConn = CreateObject("ADODB.Connection")
Set oCommand =   CreateObject("ADODB.Command")
oConn.Provider = "ADsDSOObject"
oConn.Open "Active Directory Provider"

Set oCommand.ActiveConnection = oConn
oCommand.CommandText = _
    "Select Name, Location from '"& strDomain &"' " _
        & "Where objectClass='computer'"

oCommand.Properties("Page Size") = 1000
oCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set oRS = oCommand.Execute
oRS.MoveFirst

Do Until oRS.EOF
    results.WriteLine oRS.Fields("Name").Value
    oRS.MoveNext
Loop

"lee" <l...@discussions.microsoft.com> wrote in message

news:096052A1-4AF9-4696-8B62-AF4F44DF671C@microsoft.com...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Mueller [MVP]  
View profile  
 More options Jun 13 2008, 3:42 pm
Newsgroups: microsoft.public.scripting.vbscript
From: "Richard Mueller [MVP]" <rlmueller-nos...@ameritech.nospam.net>
Date: Fri, 13 Jun 2008 10:42:04 -0500
Local: Fri, Jun 13 2008 3:42 pm
Subject: Re: help needed moving mulitple computer accounts
The easiest way to have the script document what happens (to a text file) is
to use Wscript.Echo statements, run the script at a command prompt using
cscript, and redirect the output to a text file. The script already echos
when a computer is not found, so you can add a Wscript.Echo statement where
the script moves computers. If the script is saved in the file
MoveComputers.vbs you can use a command similar to below at a command
prompt:

cscript //nologo MoveComputers.vbs > report.txt

The "//nologo" parameter suppresses logo information. It takes more work to
use the FileSystemObject to create and write to a log file, but this offers
more flexibility. You can also both echo to the console and write to the
file, so you can monitor progress as the script runs (and not worry if it is
hung up), while still having a log for later. The version below (corrected
for the mistakes found earlier), both echos to the console and writes to a
file. No need to redirect the output. The name and path of the files are
hard coded:
===========
Option Explicit

Dim strFile, strTargetOU, objFSO, objFile, objOU
Dim objRootDSE, strDNSDomain, objTrans, strNetBIOSDomain
Dim strComputer, strComputerDN, objComputer
Dim strLog, objLog

Const ADS_NAME_INITTYPE_DOMAIN = 1
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1179 = 1
Const ForAppending = 8
Const ForReading = 1
Const OpenAsASCII = 0
Const CreateIfNotExist = True

' Specify text file of computer NetBIOS names.
strFile = "c:\scripts\Computers.txt"

' Specify log file.
strLog = "c:\scripts\MoveComputers.log"

' Specify target OU to move computer objects into.
strTargetOU = "ou=Detention,ou=West,dc=MyDomain,dc=com"

' Open the file for read access.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, ForReading)

' Open the log file for appending.
Set objLog = objFSO.OpentTextFile(strlog, _
    ForAppending, CreateIfNotExist, OpenAsASCII)
' Write to the log file.
objLog.WriteLine "MoveComputers.vbs log file"
objLog.WriteLine "Started: " & CStr(Now())

' Bind to the target OU.
Set objOU = GetObject("LDAP://" & strTargetOU)

' Determine DNS domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")

' Use the NameTranslate object to find the NetBIOS domain name from
' the DNS domain name.
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_TYPE_NT4, strDNSDomain
objTrans.Set ADS_NAME_TYPE_1179, strDNSDomain
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
' Remove trailing backslash.
strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)

' Use the NameTranslate object to convert computer NetBIOS
' names to Distinguished Names.
objTrans.Init ADS_NAME_INITTYPE_DOMAIN, strNetBIOSDomain

' Read lines from the file.
Do Until objFile.AtEndOfStream
    strComputer = Trim(objFile.ReadLine)
    If (strComputer <> "") Then
        ' Convert NetBIOS name to DN.
        ' NetBIOS name must have "$" appended to end.
        ' Trap error if computer not found.
        On Error Resume Next
        objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain _
            & "\" & strComputer & "$"
        If (Err.Number <> 0) Then
            On Error GoTo 0
            Wscript.Echo "Computer not found: " & strComputer
            objLog.WriteLine strComputer & " not found"
        Else
            On Error GoTo 0
            strComputerDN = objTrans.Get(ADS_NAME_TYPE_1179)
            ' Bind to the computer object.
            Set objComputer = GetObject("LDAP://" & strComputerDN)
            ' Move the computer object to the target OU.
            objOU.MoveHere objComputer.AdsPath, vbNullString
            Wscript.Echo strComputer & " moved"
            objLog.WriteLine strComputer & " moved"
        End If
    End If
Loop

objLog.WriteLine "Finished: " & CStr(Now())
objFile.Close
objLog.Close
Wscript.Echo "Done"

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"lee" <l...@discussions.microsoft.com> wrote in message

news:096052A1-4AF9-4696-8B62-AF4F44DF671C@microsoft.com...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ThatsIT.net.au  
View profile  
 More options Jun 13 2008, 4:05 pm
Newsgroups: microsoft.public.scripting.vbscript
From: "ThatsIT.net.au" <me@work>
Date: Sat, 14 Jun 2008 00:05:27 +0800
Local: Fri, Jun 13 2008 4:05 pm
Subject: Re: help needed moving mulitple computer accounts
Ok looks like I misread you post,

"ThatsIT.net.au" <me@work> wrote in message

news:FFE8237C-40EA-467A-AF0E-F41C29BF86C0@microsoft.com...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
lee  
View profile  
 More options Jun 16 2008, 6:46 pm
Newsgroups: microsoft.public.scripting.vbscript
From: lee <l...@discussions.microsoft.com>
Date: Mon, 16 Jun 2008 11:46:03 -0700
Local: Mon, Jun 16 2008 6:46 pm
Subject: Re: help needed moving mulitple computer accounts
Richard,
   I tried running the script usicng Cscript and got the following error:
C:\Lee\moveou.vbs(30, 1) Microsoft VBScript runtime error: Object doesn't
support this property or method: 'OpentTextFile'

I tried creating the Movedcomputer.log file but got the same error. I have
only changed the file locations and the OU path to suit our environment.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
lee  
View profile  
 More options Jun 17 2008, 1:46 pm
Newsgroups: microsoft.public.scripting.vbscript
From: lee <l...@discussions.microsoft.com>
Date: Tue, 17 Jun 2008 06:46:04 -0700
Local: Tues, Jun 17 2008 1:46 pm
Subject: Re: help needed moving mulitple computer accounts
Nevermind, I found the typo that was generating the error. Had to clean my
bifocals. ;)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
KenBag  
View profile  
 More options Nov 5, 5:19 pm
Newsgroups: microsoft.public.scripting.vbscript
From: KenBag <Ken...@discussions.microsoft.com>
Date: Thu, 5 Nov 2009 09:19:01 -0800
Local: Thurs, Nov 5 2009 5:19 pm
Subject: Re: help needed moving mulitple computer accounts
Good information!

I need to be able to move computer accounts from one OU to another as well,
but I need the script to search for specific computer names in the Computers
OU for computers that have joined the domain. Any computers that start with
"L1", move it to the correct OU. I also need it to run in real-time once the
computer has joined to the domain.

Thanks for the help.
--
KenB


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google