From workgroup to join domain

(imported topic written by SystemAdmin)

Hi,

I have run a bat file from workgroup to join domain. I getting below error when run my batch file on client PC (A specified logon session does not exist. It may already have been terminated.)

C:\Program Files\BigFix Enterprise\BES Client__BESData\actionsite>netdom /Domai

Searching PDC for domain…

Found PDC \EXCHANGE

Connecting to \EXCHANGE with user account …

Querying domain information on PDC \ …

Querying domain information on computer \…

Computer \TEST1 is currently in workgroup WORKGROUP.

Verifying if computer account exists on \EXCHANGE …

A specified logon session does not exist. It may already have been terminated.

Techlab

(imported comment written by MattBoyd)

NetDom 1.8? That seems like a very old version of NetDom… What version of Windows are you using this on?

A newer version should be included in the Windows XP Support tools: http://www.microsoft.com/downloads/details.aspx?FamilyId=49AE8576-9BB9-4126-9761-BA8011FABF38&displaylang=en

(imported comment written by SystemAdmin)

But i try manually on client PC click my bacth file is work… It could not work when used Bigfix deploy.

I try below commad also getting same error

  1. waithidden c:\joindomain.bat

  2. runhidden c:\joindomain.bat

  3. dos c:\joindomain.bat

(imported comment written by SystemAdmin)

As Boyd said, get a newer version of netdom! The one he linked will work fine with Windows XP, however if you are dealing with Win2k clients, you need to use the version that came with the Windows 2000 resource kit found here:

Also, ditch the batch files-- just put the commands into the action script. Example:

__waithidden 
"__Download/netdom.exe" join 
{computer name
} /domain:yourdomain.com /UserD:account /PasswordD:Password!

Notice the {computer name} in there-- that is important because the command requires the name of the computer and this will use relevance to insert it into the action. There is also an optional /OU switch you can use to specify where you want the items added, but you need to phrase it like an LDAP query: “OU=organizational unit,DC=domain,DC=tld”

For good measure I throw an “action requires restart” at the end of the script, but I don’t actually make the machine reboot.

To determine relevance for this action, the best way I have found to check if the machine is on a domain or not is to see if the NETLOGON service is running:

state of service 
"netlogon" != 
"Running"

Good luck!

(imported comment written by BenKus)

Note: Standard warning about distributing passwords!

Ben

(imported comment written by SystemAdmin)

Thanks Ben, the command is working pretty fine…

Techlab

(imported comment written by SystemAdmin)

We just run the commands, through bigfix

Remove from domain

action requires restart action parameter query 
"Domain" with description 
"Please enter the Domain Name of existing Domain" action parameter query 
"User" with description 
"Please enter the user name with rights to remove server from domain" action parameter query 
"Password" with description 
"Please enter the password for user specified in previous entry" 

if
{name of operating system contains 
"2000"
} 

if 
{(not exists file (pathname of system folder & 
"\netdom.exe"))
} prefetch netdom.exe sha1:8d22f02bb33ce510b5bf2a427d878f03e29f4126 size:115984 http:
//<SERVER>/Shared/Component_Install/Netdom_win2000/netdom.exe COPY __download\netdom.exe 
{pathname of system folder
}\netdom.exe endif endif DOS NETDOM REMOVE 
{computer name as uppercase
} /DOMAIN:
{parameter 
"Domain" of action
} /userD:
{parameter 
"User" of action
} /passwordD:
{parameter 
"Password" of action
} RESTART

join Domain

action requires restart action parameter query 
"Domain" with description 
"please enter the Domain Name" action parameter query 
"User" with description 
"Please enter the user name with rights to add to domain" action parameter query 
"Password" with description 
"Please enter the Password for user specified in previous entry" 

if
{name of operating system contains 
"2000"
} 

if 
{(not exists file (pathname of system folder & 
"\netdom.exe"))
} prefetch netdom.exe sha1:8d22f02bb32ce510b5bf2a432d878f03e29f4156 size:115984 http:
//<SERVER>/Shared/Component_Install/Netdom_win2000/netdom.exe COPY __download\netdom.exe 
{pathname of system folder
}\netdom.exe endif endif DOS NETDOM JOIN 
{computer name as uppercase
} /DOMAIN:
{parameter 
"Domain" of action
} /userD:
{parameter 
"User" of action
} /passwordD:
{parameter 
"Password" of action
} RESTART

(imported comment written by mcalvi91)

to join our systems do AD via bigfix we adapted some VB code that used WMI. See below. This will drop the computer object into the appropriate OU if the userid and password you give it have rights to that OU.

' Script Name:  JoinToAD.vbs 
' Source: http://cwashington.netreach.net/depo/view.asp?Index=877&ScriptType=vbscript and MS Script Center 
' Description: joins a Windows server computer to the domain. 
' Requirements: 
'    - only works on Windows XP (and higher) 
'    - run the script on the computer that needs to be joined 
'    - specify a domain user account that has permissions to join to the domain 
'    - run with CScript.exe to view output     On Error Resume Next   
' specify constants Const JOIN_DOMAIN = 1 Const ACCT_CREATE = 2 Const ACCT_DOMAIN_JOIN_IF_JOINED = 32   
' prepopulate variables varExitErrorLevel = 0   
'check arguments for user and other info. (will remove later) If WScript.Arguments.Length > 0 Then strCommand = 
"Join" For varIndex = 0 To (WScript.Arguments.Length - 1) arrArgument = Split(WScript.Arguments(varIndex), 
":", -1, vbTextCompare) strArgument = arrArgument(0) If Ubound(arrArgument) = 0 Then Select Case LCase(strArgument) Case 
"/reboot" flgReboot = True Case Else subUsage End Select Else strArgumentValue = arrArgument(1) wscript.echo strArgument Select Case LCase(strArgument) Case 
"/domain" strDomain = strArgumentValue Case 
"/ou" strOU = strArgumentValue Case 
"/user" strUser = strArgumentValue Case 
"/password" strPassword = strArgumentValue Case Else subUsage End Select End If Next Else subUsage End If   
' get the host name Set objNetwork = CreateObject(
"WScript.Network") strHostName = objNetwork.ComputerName Set objNetwork = Nothing   
'get the computer object via WMI Set objWMIComputer = GetObject(
"winmgmts:{impersonationLevel=Impersonate}!\\" & strHostName & "\root\cimv2:Win32_ComputerSystem.Name=
'" & strHostName & "'
")   
'check for an error If Err = 0 Then 
'Select Case strCommand 
'    Case "Join" subDisplay 
"Joining computer to domain." & vbCrLf & 
"Hostname: " & strHostName & vbCrLf & 
"Domain: " & strDomain &  vbCrLf & 
"Username: " & strUser wscript.echo Err 
'join it to AD at the appropriate OU varWMIJoinReturnValue = objWMIComputer.JoinDomainOrWorkGroup(strDomain, strPassword, strUser, JOIN_DOMAIN + ACCT_CREATE) wscript.echo Err 
'do some error checking. If Err = 0 Then If varWMIJoinReturnValue = 2224 Then subDisplay 
"The computer account already exists." If Not strOU = 
"" Then subDisplay 
"The computer account will stay in it's current OU." varWMIJoinReturnValue = objWMIComputer.JoinDomainOrWorkGroup(strDomain, strPassword, strUser, strOU, JOIN_DOMAIN) If Not varWMIJoinReturnValue = 0 Then subDisplay fncErrorMessage(varWMIJoinReturnValue, 
"", True) Else If Not varWMIJoinReturnValue = 0 Then subDisplay fncErrorMessage(varWMIJoinReturnValue, 
"", True) End If Else subDisplay fncErrorMessage(Hex(Err.Number), Err.Description, True) End If 
'                Case "Else" 
'        subDisplay fncErrorMessage(99990, "Internal error; unrecognized command.", True) 
'End Select 
'reboot as needed If varExitErrorLevel = 0 Then subDisplay 
"Finished succesfully." & vbCrLf & 
"Please reboot to apply changes." If flgReboot = True Then Set objOperatingSystems = GetObject(
"winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery(
"select * from Win32_OperatingSystem where Primary=true") subDisplay 
"Rebooting..." For each objOperatingSystem in objOperatingSystems objOperatingSystem.Reboot() Next End If End If Else subDisplay fncErrorMessage(Hex(Err.Number), Err.Description, True) End If Set objWMIComputer = Nothing WScript.Sleep 1000 WSCript.Quit varExitErrorLevel     Sub subUsage() 
'WScript.Echo "Usage: cscript.exe NetDomOU.vbs /Domain:domain [/User:user] [/Password:password]" & vbCrLf & _ 
'WScript.Echo "Usage: cscript.exe NetDomOU.vbs Join|Unjoin|Remove /Domain:domain [/OU:ou] [/User:user] [/Password:password]" & vbCrLf & _ 
' vbCrLf & "Join: Joins the computer to a domain." & vbCrLf & _ 
'vbCrLf & "Unjoin: Unjoin the computer from a domain. No other arguments required. The domain computer account will not be deleted!" & vbCrLf & _ 
'vbCrLf & "Remove: Unjoin the computer from a domain and delete the domain computer account. No other arguments required. Administrative permissions on the domain are required! " &_ 
'        "(The /user-argument is ignored). Wait for replication to finish before rejoining the computer!" & vbCrLf & _ 
' vbCrLf & "/Domain: Name of the domain." & vbCrLf & _ 
'vbCrLf & "/User: The usersaccount used to execute the command, using the domain\username or username@domain notation! Leave username and password empty to use callers credentials." & vbCrLf & _ 
'vbCrLf & "/OU: The full 'distinguished name
' of the organisational unit where the new domain computer account will be created when joining a domain. " & _ 
'        "Example /OU:""OU=myOU, DC=domain, DC=com"". The name must be between quotes! Leave empty to add the computer to the default 'Computers
'-container. " & vbCrLf & _  
'vbCrLf & "/Reboot: Reboot the computer if Join/Unjoin/Remove whas succesfull." & vbCrLf 
'WScript.Sleep 1000 
'WScript.Quit 1 WScript.Echo 
"Usage: cscript.exe jointoAD.vbs /Domain:domain [/User:user] [/Password:password]" & vbCrLf & _ vbCrLf & 
"/Domain: Name of the domain." & vbCrLf & _ vbCrLf & 
"/User: The usersaccount used to execute the command, using the domain\username or username@domain notation! Leave username and password empty to use callers credentials." & vbCrLf & _ vbCrLf & 
"/Reboot: Reboot the computer if join was succesfull." & vbCrLf WScript.Sleep 1000 WScript.Quit 1 End Sub     sub subDisplay(strOutput) If Instr(1, WScript.FullName, 
"cscript.exe", vbTextCompare) > 0 Then WScript.Echo strOutput & vbCrLf End If End Sub     Function fncErrorMessage(varErrorNumber, strErrorDescription, flgSetExitErrorLevel) If strErrorDescription = 
"" Then 
'List of 'system error codes
' and 'network management error codes
' Select Case varErrorNumber Case 5 strErrorDescription = 
"Access is denied" Case 87 strErrorDescription = 
"The parameter is incorrect" Case 110 strErrorDescription = 
"The system cannot open the specified object" Case 1323 strErrorDescription = 
"Unable to update the password" Case 1326 strErrorDescription = 
"Logon failure: unknown username or bad password" Case 1355 strErrorDescription = 
"The specified domain either does not exist or could not be contacted" Case 2224 strErrorDescription = 
"The account already exists" Case 2691 strErrorDescription = 
"The machine is already joined to the domain" Case 2692 strErrorDescription = 
"The machine is not currently joined to a domain" End Select End If fncErrorMessage = 
"Error: " & varErrorNumber & 
". " & strErrorDescription & 
"." If flgSetExitErrorLevel Then varExitErrorLevel = 1 End Function

(imported comment written by nberger91)

Anyone have a Fixlet using the secure parameter (9+ client) to join pc to domain ?

1 Like