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
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)
Please log in to answer
![](/build/static/general/appdeploy_logo.png)
so that the conversation will remain readable.