RE: LDAP query on subdomain to know all computer accounts in a OU
- From: "SubnetJO" <SubnetJO@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 6 Oct 2005 02:50:04 -0700
I think there is something to correct.
Fist of all, the setting of the constant "ADS_SCOPE_SUBTREE" make me suppose
you want to list all the computers under the selected path.
Well, I think you shoul set that constant as follow:
ADS_SCOPE_SUBTREE = 2 (2, and not 6)
I didn't studied your code very much, but setting that constant as shown,
you shouldn't receive errors.
But you'll not receive any result too!
To show the result you should add some code at the end of your script.
Try this:
Do Until objRecordSet.EOF
wscript.echo objRecordSet.Fields("Name").Value
objRecordSet.MoveNext
loop
Of course, if you run the script with wscript (double clik on it), you'll
receive a popup message for each computer you have in the selected path! (may
be hundreds!).
Better is to execute the script from "cscript" (command window).
To be shure you script is not executed wth "wscript.exe", you can add some
code at the beginning of the script. Something like this (simple example):
If Instr(1,wscript.fullname,"wscript",1) then
MSGBOX "Use this script from command line." & vbcrlf & vbcrlf & "Type:" &
vbcrlf & " cscript /nologo computerlist.vbs /?" & vbcrlf & vbcrlf & "to
know about the sintax.",+vbinformation,"ComputerList"
wscript.quit
end if
This example suppose you script is named "computerlist.vbs" (you can use the
name you like, of course) and that you have written some code to display an
help message, shown if the script user uses the "/?" switch at the command
line.
I hope this can help.
Have a good job!
SubnetJO
"Leap77" ha scritto:
> Hello all,
>
> I want to query a domain like that example.exam.net and I try to do it like
> this and doesn't functions, someone can help me?
>
> Const ADS_SCOPE_SUBTREE = 6
> Set objConnection = CreateObject("ADODB.Connection")
> Set objCommand = CreateObject("ADODB.Command")
> objConnection.Provider = "ADsDSOObject"
> objConnection.Open "Active Directory Provider"
> Set objCommand.ActiveConnection = objConnection
> objCommand.CommandText = "SELECT Name FROM
> 'LDAP://OU=Granollers,OU=Barcelona,DC=example,DC=exam,DC=net' WHERE
> objectClass='computer' "
>
> objCommand.Properties("Page Size") = 1000
> objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
> Set objRecordSet = objCommand.Execute
> objRecordSet.MoveFirst
>
>
> Thanks all,
.
- Prev by Date: Re: List machine accounts in local groups via scripting?
- Next by Date: RE: Sorry its not a window 2003 server .. its NT 4.0 sever!!!
- Previous by thread: List machine accounts in local groups via scripting?
- Next by thread: RE: Sorry its not a window 2003 server .. its NT 4.0 sever!!!
- Index(es):
Relevant Pages
|