Error DataBase-One Place all Solutions Forums Blog Glossary    Contact Us
Search  
   
Browse by Category
Error DataBase-One Place all Solutions .: Operating Systems .: Windows Operating Systems .: Windows Scripts and Batch Files .: VB Script to Find PC in Active Directory

VB Script to Find PC in Active Directory

On Error Resume Next

PCName = InputBox("Enter Computer Name?")

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
"SELECT ADsPath FROM 'LDAP://dc=microsoft,dc=com' WHERE objectCategory='computer' " & _
"AND name=' " & PCName & "'"
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields("ADsPath").Value
PCVar = objRecordSet.Fields("ADsPath").Value
objRecordSet.MoveNext
Loop

IF PCVar = "" then
WScript.Echo "No Computer of that name was found in the directory"
END IF


How helpful was this article to you?

Related Articles

article How to extract details from Active Directory using Script
' This will create a text file listing...

(No rating)  3-6-2008    Views: 151   
article VB Script to Find Service Pack Version
strComputer = "."Set...

(No rating)  3-24-2008    Views: 172   
article How to Import or Export Active Directory data to a file using CSVDE / LDIFDE commands (Directory Exchange)
Import or Export Active Directory data to a...

(No rating)  3-7-2008    Views: 348   

User Comments

Add Comment
No comments have been posted.