Need vbs script to add computer in the domaine (OU )

Discussion in 'Scripting' started by lolo1790, Sep 8, 2008.

  1. lolo1790

    lolo1790 Guest

    i need vbs script to add computer in domain (OU ) with user and password.
    i need write each information in windows , is it possible, because i don't
    find this script.

    Thanks
     
    lolo1790, Sep 8, 2008
    #1
    1. Advertisements

  2. I have used a script similar to below to join a computer to a domain. The
    username and password are hardcoded, as are the domain and OU information:
    ============
    ' JoinDomain.vbs
    ' VBScript program to join a computer to a domain.
    ' The computer account is created in Active Directory.
    ' The computer must have XP or above.
    ' The AD must be W2k3 or above.
    ' See c:\Windows\debug\NetSetup.log for details.

    Option Explicit

    Dim strDomain, strUser, strPassword
    Dim objNetwork, strComputer, objComputer, lngReturnValue
    Dim strOU

    Const JOIN_DOMAIN = 1
    Const ACCT_CREATE = 2
    Const ACCT_DELETE = 4
    Const WIN9X_UPGRADE = 16
    Const DOMAIN_JOIN_IF_JOINED = 32
    Const JOIN_UNSECURE = 64
    Const MACHINE_PASSWORD_PASSED = 128
    Const DEFERRED_SPN_SET = 256
    Const INSTALL_INVOCATION = 262144

    strDomain = "MyDomain"
    strPassword = "zXy321q$"
    strUser = "administrator"
    strOU = "ou=Computers,ou=West,dc=MyDomain,dc=com"

    Set objNetwork = CreateObject("WScript.Network")
    strComputer = objNetwork.ComputerName

    Set objComputer = GetObject("winmgmts:" _
    & "{impersonationLevel=Impersonate,authenticationLevel=Pkt}!\\" & _
    strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
    strComputer & "'")

    lngReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
    strPassword, strDomain & "\" & strUser, strOU, _
    JOIN_DOMAIN + ACCT_CREATE)

    Wscript.Echo "ReturnValue = " & CStr(lngReturnValue)
     
    Richard Mueller [MVP], Sep 8, 2008
    #2
    1. Advertisements

  3. lolo1790

    lolo1790 Guest

    Thanks you
    i would like with interactive windows, i would write each parameter in
    little windows like " domain " "user" and password.

    Thanks.
     
    lolo1790, Sep 9, 2008
    #3
  4. You can use the InputBox function to prompt for information. For example (in
    part):

    strDomain = InputBox("Enter the NetBIOS name of the domain")
    strUser = InputBox("Enter administrator name")
    strPassword = InputBox("Enter password")
    strOU = InputBox("Enter the DN of the OU where computer account created")

    --
    Richard Mueller
    MVP Directory Services
    Hilltop Lab - http://www.rlmueller.net
    --
     
    Richard Mueller [MVP], Sep 9, 2008
    #4
  5. lolo1790

    lolo1790 Guest

    With the line "strOU = InputBox("Enter the DN of the OU where computer
    account created") "

    I don't know what to write because my OU is applications/platon but what
    else form i must write in this box ?

    Thanks


     
    lolo1790, Sep 9, 2008
    #5
  6. You must use the Distinguished Name (DN) of the Organizational Unit. This is
    the only value that is sure to uniquely identify the OU. For example, the
    value might be similar to:

    ou=Sales,ou=West,dc=MyDomain,dc=com

    It might be possible to have the script construct the DN from the Relative
    Distinguished Name (RDN) of the OU, but that's a bit risky. The RDN in my
    example above is "Sales", but that is not enough information in this case to
    identify the OU. If, however, you know that the OU is at the root of the
    domain (the OU is not a child of another OU, as in my example), the script
    could determine the DNS name of the domain ("dc=MyDomain,dc=com" in my
    example) from the RootDSE object and construct the DN of the OU from the
    RDN. For example:
    ==========
    Set objRootDSE = GetObject("LDAP://RootDSE")
    strDNSDomain = objRootDSE.Get("defaultNamingContext")

    strRDN = InputBox("Enter name of the OU")
    strOU = "ou=" & strRDN & "," & strDNSDomain
    =========
    Otherwise, you must either know the Distinguished Name of the OU or hard
    code the value in the script.

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

     
    Richard Mueller [MVP], Sep 9, 2008
    #6
  7. lolo1790

    lolo1790 Guest

    See my domain

    in fact it's like that

    "OU=Platon,ou=Applications,dc=adint,dc=imr,dc=francetelecom,dc=com"

    So in the last box i must write all this information or only
    "OU=Platon,ou=Applications "

    Thanks

     
    lolo1790, Sep 10, 2008
    #7
  8. lolo1790

    lolo1790 Guest

    i have a message ""returnvalue=87", what is this message ?

    Thanks.

     
    lolo1790, Sep 10, 2008
    #8
  9. I doubt anyone knows what the numbers mean. Check the log file at:

    c:\Windows\debug\NetSetup.log

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

     
    Richard Mueller [MVP], Sep 11, 2008
    #9
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.