Verify if Computer Object Exists

email me

This allows you to check to see if a computer object exists in Active Directory or not. I’m using it to verify a machine has been added to the domain during post setup.

On Error Resume Next

strComputer = "COMPUTERNAME"
strDomain = "DOMAIN"

Set objComputer = GetObject("WinNT://" & strDomain & "/" & strComputer & ",computer")
If (Err.Number = 0) Then
   On Error GoTo 0
   Wscript.Echo "Computer object exists in AD."
Else
   On Error GoTo 0
   Wscript.Echo "Computer object does not exist in AD."
End If