RE: LDAP query on subdomain to know all computer accounts in a OU

Tech-Archive recommends: Speed Up your PC by fixing your registry



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,
.



Relevant Pages

  • Re: Finding users in local admin groups
    ... > Here is a vbscript that you can run against a remote computer that moves ... > *local* users except 'Administrator) from the Administrators group to the ... You should also add to the script logging to a file of the ... > you moved on what computers. ...
    (microsoft.public.win2000.security)
  • Re: Change local administrator password ? through GPO or push script ?
    ... I would like to change the local administrator password of every computers member of my AD domain but I am not sure of the best method. ... Create a vbs script that points to the local computer and then deploy this script by GPO. ... This attribute will permit to know wich admin password is configured for this machine. ...
    (microsoft.public.windows.server.active_directory)
  • Re: Not so Newbie
    ... The script is designed for situations like yours. ... wit 35+ computers and to go to each of those computers to individualy ... Prompt for an executable to run on each remote computer in the group. ... so you know where the deployment failed. ...
    (microsoft.public.windows.server.scripting)
  • Re: VBscript that restart the domain comptuer
    ... If you have a shutdown script that cleans up the profiles, ... permissions can restart all computers in a list remotely. ... I have already VB script I ...
    (microsoft.public.windows.server.active_directory)
  • Re: Sending computer name to txt file if file didnt copy?
    ... look intot he MSI etc suggestion. ... 150 computers and dont have access to AD to do it that way. ... Const OverwriteExisting = True ... This modified version of your script will inform you if there ...
    (microsoft.public.scripting.vbscript)