Join Domain VBS script - any way to remove PC before joining?
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??
https://dl.dropbox.com/u/119117/kace/test.vbs
Code:
Const JOIN_DOMAIN = 1 Const ACCT_CREATE = 2 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
Answers (1)
Please log in to answer
Posted by:
jagadeish
12 years ago
Check with below code..
Comments:
-
Where do I add this? At the end of the script? Beginning? And this 1 line should delete it? - sfigg 12 years ago
-
(for some reason I don't think the code fully shows up) - sfigg 12 years ago
-
Sorry we are working to address this problem right now, your code should appear as expected shortly. - bkelly 12 years ago
-
Thanks Bob... - jagadeish 12 years ago
-
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. - sfigg 12 years ago
-
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. - sfigg 12 years ago