/bundles/itninjaweb/img/Breadcrumb_cap_w.png
I am testing querying AD for some information. Here, I want the code to echo if it finds my machine name in the domain.

I created this in a notepad (changed the values in the code according to my domain and machine name and saved it as a .vbs file). Went to the command prompt and ran the .vbs file. IT comes back with this error:

C:\WINDOWS>cscript c:\temp\vbtest.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

c:\temp\vbtest.vbs(22, 4) Microsoft VBScript compilation error: Expected stateme
nt

### Code below ##

Option Explicit

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = _
"<LDAP://dc=mysecondarydomain,dc=myprimary domain,dc=com>;(objectCategory=computer)" & _
";distinguishedName,name;subtree"

Set objRecordSet = objCommand.Execute

While Not objRecordSet.EOF

If objRecordSet.Fields("Name") = "mymachinename" Then
Wscript.Echo objRecordSet.Fields("Name")
Wscript.Echo "[" & objRecordSet.Fields("distinguishedName") & "]"
Else
objRecordSet.MoveNext
EndIF

Wend
objConnection.Close
0 Comments   [ - ] Hide Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
Answer this question or Comment on this question for clarity

Answers

0
I belive you would need a space between your End IF
Answered 01/21/2005 by: TomB
Orange Belt

Please log in to comment
0
Your right...you need a space between END and IF
Answered 02/18/2005 by: strakm
Senior Yellow Belt

Please log in to comment