Results 1 to 11 of 11

Thread: Need vbs script to add computer in the domain (OU )

  1. #1
    lolo1790 Guest

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

    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

  2. #2
    Richard Mueller [MVP] Guest

    re: Need vbs script to add computer in the domain (OU )

    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)

  3. #3
    lolo1790 Guest

    re: Need vbs script to add computer in the domain (OU )

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

  4. #4
    Richard Mueller [MVP] Guest

    re: Need vbs script to add computer in the domain (OU )

    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")

  5. #5
    lolo1790 Guest

    re: Need vbs script to add computer in the domain (OU )

    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 ?

  6. #6
    Richard Mueller [MVP] Guest

    re: Need vbs script to add computer in the domain (OU )

    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.

  7. #7
    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 "

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

    I doubt anyone knows what the numbers mean. Check the log file at:

    c:\Windows\debug\NetSetup.log

  8. #8
    Join Date
    Nov 2010
    Posts
    2

    re: Need vbs script to add computer in the domain (OU )

    A alternative : You need to download some extra software
    amd64fre_GRMRSATX_MSU (this for the netdom win7 64bit)
    x86fre_GRMRSATX_MSU (this for the netdom win7 32 bit)
    You need the netdom for windows XP. check the internet for windowsxP-KB838079-supporttools
    If you need to remove Kaspersky use kavremover9 download from kaspersky ( you need to remove kaspersky if you have the kaspersky admin kit installed) deployment....
    you need to build the scripts and copy them to the netlogon from the DC.
    Then you start the scripts with a admin user. (because of the full control local and domain wide).
    Check the structure in the scripts i build some subdirs (maps)
    XP
    vista
    W7
    and add subs inside 32 and 64

    ______script 1 (batch) start.cm ( start this script with the administrator from the domain.

    REM IF YOU WANT TO REMOVE KASPERSKY
    copy \\%logonserver%\netlogon\kavremover9.exe %windir%

    c:
    cd\
    cd %windir%
    REM CHECK WELKE VERSIE BIJ DE KLANT IS GEINSTALLEERD!!!!!! Verwijder de ;

    ;call kavremover9.exe kav2009x64
    ;call kavremover9.exe kav6
    ;call kavremover9.exe kav7
    ;call kavremover9.exe kav2009
    ;call kavremover9.exe kis6
    ;call kavremover9.exe kis7
    ;call kavremover9.exe kis2009
    ;call kavremover9.exe kis2009x64
    ;call kavremover9.exe kav6fs
    ;call kavremover9.exe kav6wks

    :: ------ OS analyze ------
    if %OS%==Windows_NT goto setOS
    GOTO end


    :setOS
    VER | FIND "Windows 2000 [Version 5" >NUL && SET WINVER=W2K
    VER | FIND "Windows XP [Version 5" >NUL && SET WINVER=WXP
    VER | FIND "Windows [Version 6" >NUL && SET WINVER=WVista
    VER | FIND "Windows [Version 6.1.7600" >NUL && SET WINVER=W7



    rem Copy the join script to c:\windows
    copy \\%logonserver%\netlogon\runme.cmd %windir%

    if %WINVER%==W2K
    goto einde

    if %WINVER%==WXP goto xp

    if %WINVER%==WVista goto Vista

    if %WINVER%==WXP goto W7

    if %WINVER%==WXP goto XP

    goto einde

    :xp
    @echo off
    Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
    REG.exe Query %RegQry% > checkOS.txt
    Find /i "x86" < CheckOS.txt > StringCheck.txt
    If %ERRORLEVEL% == 0 (
    copy \\%logonserver%\netlogon\XP\86\netdom.exe %windir%
    )
    ELSE (
    copy \\%logonserver%\netlogon\XP\64\netdom.exe %windir%
    )
    goto verder


    :vista

    @echo off
    Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
    REG.exe Query %RegQry% > checkOS.txt
    Find /i "x86" < CheckOS.txt > StringCheck.txt
    If %ERRORLEVEL% == 0 (
    copy \\%logonserver%\netlogon\vista\86\netdom.exe %windir%
    )
    ELSE (
    copy \\%logonserver%\netlogon\vista\64\netdom.exe %windir%
    )

    goto verder

    :w7

    @echo off
    Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
    REG.exe Query %RegQry% > checkOS.txt
    Find /i "x86" < CheckOS.txt > StringCheck.txt
    If %ERRORLEVEL% == 0 (
    copy \\%logonserver%\netlogon\w7\86\netdom.exe %windir%
    )
    ELSE (
    copy \\%logonserver%\netlogon\w7\64\netdom.exe %windir%
    )

    goto verder



    :verder
    copy \\%logonserver%\netlogon\uit.reg %windir%

    copy \\%logonserver%\netlogon\add.reg %windir%

    copy \\%logonserver%\netlogon\beheerderwachtwoord.reg %windir%

    copy \\%logonserver%\netlogon\admuser.vbs %windir%



    rem Create a local admin user with password
    call c:\windows\admuser.vbs



    rem add the runonce command run once this makes the join with the network
    regedit /s %windir%\add.reg

    regedit /s %windir%\beheerderwachtwoord.reg


    rem Remove pc from domain and add to local workgroup
    call \\%logonserver%\netlogon\unjoin.vbs




    rem Herstart
    shutdown -r

    :einde
    @Echo OS wordt niet ondersteund


    ________SCRIPT 2 another batch file (runme.cmd)

    @echo off
    c:
    cd %windir%
    netdom join %COMPUTERNAME% /Domain:typehereyourdomainname /UserD:manager /PasswordD:manager
    REM in development didnt test the powershell tool yet
    REM WIN7 en VISTA
    ;powershell Add-Computer -DomainName "YOURDOMAIN"

    regedit /s %windir%\uit.reg
    c:
    cd %windir%
    del uit.reg
    del netdom.exe
    del addjoinrunonce.reg
    del beheerderwachtwoord.reg
    del admuser.vbs
    shutdown -r

    ________SCRIPT 3 JOIN.VBS

    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 = "NAMEOFDOMAIN"
    strPassword = "password"
    strUser = "administrator"

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

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

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


    _______SCRIPT 4
    unjoin.vbs
    Const NETSETUP_ACCT_DELETE = 2 'Disables computer account in domain.
    strPassword = "password"
    strUser = "administrator"

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

    Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
    strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
    strDomain = objComputer.Domain
    intReturn = objComputer.UnjoinDomainOrWorkgroup _
    (strPassword, strDomain & "\" & strUser, NETSETUP_ACCT_DELETE)

    ___admuser.vbs

    ' name of user to be created
    sNewUser = "manager"

    ' password to be set on the account
    sPassword = "manager"

    ' name of the group the user is to be added to
    sGroupname = "Administrators"

    ' get computer name, using current computer in this case
    Set oWshNet = CreateObject("WScript.Network")
    sComputerName = oWshNet.ComputerName

    ' connect to the Winnt provider
    Set oComputer = GetObject("WinNT://" & sComputerName)

    ' create the user
    Set oUser = oComputer.Create("user", sNewUser)

    oUser.SetPassword sPassword

    ' in case the user already exists, we suppress the error
    On Error Resume Next
    ' create the user
    oUser.Setinfo

    ' Add the user to the group
    Set oGroup = GetObject("WinNT://" & sComputerName & "/" & sGroupname)

    ' Use error handling in case the account is a member already
    On Error Resume Next
    oGroup.Add(oUser.ADsPath)
    On Error Goto 0
    '--------------------8<----------------------

    _____ SCRIPT reg uit.reg
    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
    "DefaultDomainName"=""
    "DefaultUserName"=""
    "AutoAdminLogon"="0"
    "DefaultPassword"=""
    "ForceAutoLogon"="0"

    ____SCRIPT REG beheerderwachtwoord.reg
    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
    "DefaultUserName"="manager"
    "AutoAdminLogon"="1"
    "DefaultPassword"="manager"
    "ForceAutoLogon"="1"
    "DefaultDomainName"=".\"

  9. #9
    Join Date
    Nov 2010
    Posts
    2

    re: Need vbs script to add computer in the domain (OU )

    I forgot the
    Add.reg
    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce]
    "startup"="\"C:\\windows\\runme.cmd\""

    Another remark:
    Windows 7 and Vista its possible that the netdom.exe must be copied inside windows\system32

  10. #10
    Join Date
    Mar 2011
    Posts
    1

    Re: Need vbs script to add computer in the domain (OU )

    Hi I was hoping I could modify this script to direct the join to a specific DC. Anybody have any ideas?

    Many thanks

  11. #11
    Join Date
    Jan 2006
    Posts
    605

    Re: Need vbs script to add computer in the domain (OU )

    Quote Originally Posted by (robin) View Post
    Hi I was hoping I could modify this script to direct the join to a specific DC. Anybody have any ideas?

    Many thanks
    You can check at the NETDOM program that comes with the windows support tools and it will also allow anyone to add machines to any of the domain and afterwards rename machines from the command lines. I think that it wont be a problem to write this into a batch file using the command called set /p to prompt for any user input where ever it is necessary.

Similar Threads

  1. Script to add a machine to domain
    By martinez7251 in forum Windows Software
    Replies: 1
    Last Post: 11-05-2010, 11:23 PM
  2. Script to Rename Computer Name in Domain
    By skepper in forum Windows Server Help
    Replies: 3
    Last Post: 10-07-2009, 10:05 AM
  3. Replies: 1
    Last Post: 18-08-2008, 10:17 PM
  4. domain logon script does not run
    By Onetoomany in forum Windows Server Help
    Replies: 4
    Last Post: 11-02-2008, 05:37 AM
  5. Unable to access domain shares from a non domain computer
    By Joe Thomas in forum Windows Server Help
    Replies: 7
    Last Post: 26-06-2006, 11:19 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,625,754.30706 seconds with 17 queries