Normally I can translate VBScript examples into working JScript but I'm
having trouble with this one. And please, no suggestions to write in in
VBS. I need the code in JScript.
I'm trying to connect to the ADSI provider in WMI in order to do deep
searches of the Active Directory for computer names.
The following VBScript code will locate a computer located anywhere in
Active Directory:
Set refWMI = GetObject("winMgmts:root\directory\LDAP")
Set colComputers = refWMI.ExecQuery("SELECT * FROM DS_Computer")
For Each refPC In colComputers
WScript.Echo refPC.DS_cn
Next
Just translating the syntax to JScript does not work. I don't get any
errors I also don't get any computer names.
Among the various syntax I've tried in JScript, this looked the most
promising to me but it didn't work (no error but no computer's returned
either).
var oLocator = new ActiveXObject("WbemScripting.SWbemLocator");
var oTarget = oLocator.ConnectServer("", "root\\directory\\LDAP");
var ePC = new Enumerator(oTarget.ExecQuery("SELECT * FROM DS_User"));
for (var oPC in ePC)
WScript.Echo(oPC.DS_cn);
I've tried placing the name of a domain controller in place of the empty
quotes on the ConnectServer line and it still didn't work.
Scott