Code Script .co.uk

Home | Scripts | Tutorials | Disclaimer | Sitemap | Contact

   Add Machine To Domain
 

Vbscript / Active Directory / Add Machine To Domain

Join a computer to an AD domain and create a computer account. Use the constants to specify extra options in the JoinDomainOrWorkGroup method of the computer object.
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 = "domainname"
strPassword = "password"
strUser = "username"

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)





Please note that a disclaimer applies to any code on this page.
 
   Actions
  Go Back
  Bookmark
  Print Page


   Menu
 
- Links
- Reference
- Script Editors
- Tutorials
- Vbscript
     - Active Directory
          - Ad User Information Query
          - Add Machine To Domain
          - Add User To Group
          - Create Group
          - Create Ou Structure
          - Enumerate Ad Users
          - Enumerate Group Members
          - Move Users And Groups Between Ous
          - Raise Domain Functional Level
     - Exchange
     - Files And Folders
     - General
     - Ms Office
     - Operating System
     - Processes And Services
     - Text Processing
     - User Interaction
     - Web Servers