Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion help needed moving mulitple computer accounts
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
 
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...
> 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


    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.

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