Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted

Hey guys and gurls,

 

We currently use FOG to image our machines with a Windows 7 Syspreped image on a windows domain on a windows server 2008 R2 dc.

 

I have written scripts to install drivers, check for updates, add to active directory,etc so the build can be deployed without user interaction :)

 

However, I would like to add a feature into this that will remove the computer with the same name on the domain. As we sometimes have to reimage a computer(s) that are already on domain, I would like a script that if it fails to add to domain using my scripts puts a txt file with the name of the PC itself onto a share/server. Then this server which is on the domain checks with a script every 5-15mins and if it sees a txt file gets its/there names and searches AD and removes the computers in question. Then the new computer will wait 5-15 mins and the run the task again, therefore it should be able to add itself to domain.

 

I can do the new computer side of scripts but need help getting a script on the server to check for the text file and then remove the associated computer from domain based on this information.

 

I thought there might be a way of on the new computer as to over rule the existing computer object.

 

Thanks in advance for your guys help,

 

Tom

Posted

By default, when a computer leaves the domain in a 2008 R2 environment, the Computer Object remains but is disabled.

 

If you then re-joined a computer (using the same name), it would automatically re-use the existing Computer Object.

 

The same applies if you re-imaged a workstation without demoting it from the domain in the first instance.

 

You only need to delete Computer Objects if you know it'll never be used again or if you changed your workstation naming structure (for example).

  • Thanks 1
Posted

Well thats what I thought at first, however if I leave the computer in AD and try to add the new computers the script fails... I have set it to check to see if it is part of domain and if not try again but that still fails the second time on all computers.

 

Heres my script which does work to add computers to domain automatically when they are not on already.

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

Dim message

Dim IP

 

 

strDomain = "domain.local"

strUser = "user"

strPassword = "password"

 

Set objNetwork = CreateObject("WScript.Network")

strComputer = objNetwork.ComputerName

 

Set objWMIService = GetObject ("winmgmts:" & "!\\" & strComputer & "\root\cimv2")

Set colAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")

 

Dim objNTInfo

Set objNTInfo = CreateObject("WinNTSystemInfo")

 

GetComputerName = lcase(objNTInfo.ComputerName)

 

newComputerName = GetComputerName

 

If newComputerName = "" Then

Wscript.quit

End If

 

Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _

strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _

strComputer & "'")

 

ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, strPassword, strDomain & "\" & strUser, "OU=ICT1,OU=Curric PC's,OU=school computers,DC=domain,DC=local", JOIN_DOMAIN + ACCT_CREATE)

 

I would apprieciate any help with a fix to an issue that could cause this not to work.

 

Tom

Posted

Well I have reimaged an ICT suite last night and they are all on domain this morning even though I didn't remove from domain first. Seems you were right :)

 

I had edited the scripts to check if on domain and if not run the script one more time to try adding it again to domain, don't know if this helped or not.

 

Thanks,

Tom

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...