I need a login script or script that rejoins a machine to a new domain. I
have over 100 workstations in the organization and I need a script that can
automate this task. Thank You

Re: I need a login script that rejoins a machine to a new domain by Pegasus

Pegasus
Mon Mar 17 07:46:28 CDT 2008


"Jay G." <JayG@discussions.microsoft.com> wrote in message
news:EA0C0ED2-33B7-4934-B936-F310370FAACF@microsoft.com...
>I need a login script or script that rejoins a machine to a new domain. I
> have over 100 workstations in the organization and I need a script that
> can
> automate this task. Thank You

Here is an untested code fragment that I picked up from
this newsgroup some time ago. Use it at your own risk!

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 = InputBox("Enter Domain name to Join")
strUser = InputBox("Enter Domain User to join domain")
strPassword = Inputbox("Enter password")

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, _
"cn=Computers,DC=mydomain,dc=com", JOIN_DOMAIN + ACCT_CREATE)

If ReturnValue = 0 Then
MsgBox "Computer added to domain under old name without error.
Proceeding to change computer name. "
Else
MsgBox "Computer not added to domain successfully. Return value: " &
ReturnValue
End If