Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm looking for a way to diss-join a machine from a domain and join a machine to a domain via scripts. I searched online and have found the following script that should join a machine to a domain but I can't seem to get it working or might just be executing it incorrectly.

Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2

strDomain = "domain"
strUser = "userAccount"
strPassword = "password"
strOU = "cn=COMPUTERS,dc=labtech,dc=COM"

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

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

objComputer.JoinDomainOrWorkGroup strDomain, strPassword, strDomain & "\" & strUser, strOU, JOIN_DOMAIN + ACCT_CREATE

I know there is the powershell command of add-computer but from what I can see, there is no way to save the login credentials.

Any and all help would be greatly appreciated. -Matt

share|improve this question
2  
How ARE you trying to run it? What happens when you do? How about setting break points or logging various variables along the way so you can confirm they are getting the proper information. –  Ƭᴇcʜιᴇ007 Aug 29 '13 at 17:19
    
I've used that exact code snippet in the past with success. The account that you assign to the variables, have you verified that it can add computers to the domain manually? Also, have you tried to assign the strDomain variable the FQDN of your domain? –  Josh R Aug 29 '13 at 18:28
    
I was trying to execute it via wscript in cmd. The script would look like its running but not do anything. No error or status messages. I was able to get something similar working using Powershell. Thanks guys. –  Mpit52 Sep 5 '13 at 14:17

1 Answer 1

I was trying to execute it via wscript in cmd. The script would look like its running but not do anything. No error or status messages. I was able to get something similar working using Powershell. Thanks guys.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.