/build/static/layout/Breadcrumb_cap_w.png

whats wrong in this VB code?

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   [ + ] Show comments

Answers (2)

Posted by: TomB 19 years ago
Orange Belt
0
I belive you would need a space between your End IF
Posted by: strakm 19 years ago
Senior Yellow Belt
0
Your right...you need a space between END and IF
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ