Here is our VBS script that we use to join the domain. Is there a way to have it delete the PC if it already exists? That's the problem we're running into. Any help here??



 Const JOIN_DOMAIN = 1



strDomain = "CUSD200.LOCAL"

strUser = "PCTECH"

strPassword = "XXX"

strOU = "ou=distwidelaptops,ou=d200computers,DC=CUSD200,DC=local"


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



0 Comments   [ + ] Show Comments


Please log in to comment



Check with below code..

Answered 06/28/2012 by: jagadeish
Red Belt

  • Where do I add this? At the end of the script? Beginning? And this 1 line should delete it?
  • (for some reason I don't think the code fully shows up)
    • Sorry we are working to address this problem right now, your code should appear as expected shortly.
  • Thanks Bob...
  • Actually...I'm stupid. I just thought that this won't work. We want to be able to delete the PC from the domain (I'm assuming it runs off the pc name). However, upon imaging, and reboot - it will sysprep, and apply a random PC name - so we don't want to remove that from the domain - we want to remove the pc name that was on there before sysprep. Not sure how to do this - I heard ADSI scripts in KBE would work, but I don't know the first thing about that.
  • If I try to run this as a preinstall task in KBE, it says that the specified domain either does not exist or could not be contacted - hmmm. ADSI is suppose to allow us to talk to AD I thought.
Please log in to comment
Answer this question or Comment on this question for clarity