Jump to content
Sign in to follow this  

Query a computer account exists in AD

Recommended Posts


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.

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


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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.