Sign in to follow this  
Followers 0
ScriptedIT

Query a computer account exists in AD

2 posts in this topic

I've looked though ADFunctions and it does this for users but not computers. There is also a "create the computer and then see if it complained it already existed." Still I just want to know if it exists. Is this possible?

Share this post


Link to post
Share on other sites



I found this vbscript snippet which might give some hints.

CODE
Function isComputerAccountExists(host)

Dim conn, cmd , rs

Set conn = CreateObject("ADODB.Connection")

Set cmd = CreateObject("ADODB.Command")

conn.provider = "adsdsoobject"

conn.open "active directory provider"

cmd.activeconnection = conn

cmd.commandtext = ";(&(objectcategory=computer)(objectclass=computer)(cn=" & host & "));cn;subtree"

Set rs = cmd.Execute

If rs.recordcount = 0 Then

isComputerAccountExists = False

Else

isComputerAccountExists = True

End If

End Function

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0