Solved

ADSI - filtering on the winnt:// provider with javascript

Posted on 2002-07-02
11
2,191 Views
Last Modified: 2008-02-01
This silly little problem is giving me the absolute sh?ts at the moment.  I'm trying to enumerate groups and users on a particular domain, instead my script returns every damn object in the computer collection.  Examine the code below:

  var strDomain = "someDomain/someComputer";
  var Computer = GetObject("WinNT://" + strDomain);
  Computer.Filter = new Array("Group","User");
  // WScript.Echo(Computer.Filter);
  var romulus, remus; //enumeration placeholders
  romulus = new Enumerator(Computer);
  for(;!romulus.atEnd();romulus.moveNext())
    {
    remus = romulus.item();
    WScript.Echo(remus.Name);
    }
  // WScript.Echo("done");

basically this line
  Computer.Filter = new Array("Group","User");
is not doing what the advertisements say, instead of the output being limited to users and groups i'm getting services, devices etc.  I can comment out the line or assign all sorts of rubbish to the variable and makes absolutely no difference to the output.  What am i doing wrong?

Target and Source computer are the same - Winnt 4.0 SP6 with ads.exe (file version 4.71.1015.0) applied.

Regards,

etc.
0
Comment
Question by:klalakomacoi
11 Comments
 
LVL 9

Expert Comment

by:schmiegu
ID: 7137044
I'm not familiar with JScript, so I will try to translate it to VBScript.

I believe, the problem is in this line:
   Computer.Filter = new Array("Group","User");
I never saw that you could filter by 2 parameters at once

Computer.Filter = Array("user")
for each remus in Computer
  wscript.echo remus.name
next
Computer.filter = Array("group")
for each romulus in Computer
  wscript.echo romulus
next
0
 
LVL 3

Author Comment

by:klalakomacoi
ID: 7137207
well the MS documentation says you can filter on two parameters at once (i'll find the documentation in question and point you to it), anyway i'll try your suggestion and give it a rip and get back to you.

unfortunately i am not allowed to use VBscript for religious reasons.

regards,

Ian

0
 
LVL 3

Author Comment

by:klalakomacoi
ID: 7296649
nope doesn't make a difference if i drop it to only one parameter in the filter statement.

sorry about leaving this question for dead for so long, buried in other crap.

i'll get that MS doco i was talking about earlier and post it.
0
 
LVL 9

Expert Comment

by:schmiegu
ID: 7297918
Since it doesn't work with only one filter parameter, there must be another problem.
You're using the 'new' keyword: I'm not familiar with JScript, but in VBScript it's not a valid keyword, while it is in VB. So maybe the line doesn't really filter the results the GetObject.
0
 
LVL 3

Author Comment

by:klalakomacoi
ID: 7297925
i've pulled out the "new" still no difference, all the objects are output and not a bit of filtering.  does this work the way its supposed to in VBscript?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 9

Expert Comment

by:schmiegu
ID: 7297945
Yes, it does. For purpose of verification I'm running this script at the moment:

Option Explicit
dim myDomains, myDom
dim myUsers, myComp
dim oFSO, oFile
set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFso.CreateTextFile("DomainUsers.csv", True)
  oFile.WriteLine("Name" & vbTab & "Full Name")
  set myUsers = GetObject("WinNT://MyDomain")
  myUsers.Filter = Array("User")
  for each myUser in myUsers
    oFile.WriteLine(myUser.Name & vbTab & myUser.FullName)
  next
oFile.Close
MsgBox "Done"

I only got user accounts. Changing the filter to "computer" only showed computers. (I only got an error, because I didn't delete the .FullName property from the script - this isn't supported by computers)
0
 
LVL 3

Author Comment

by:klalakomacoi
ID: 7298062
you're right, it works like a charm.  I'm sorry but have to leave you now, i have to do a ritual cleansing ceremony because i used VBscript.

Its obviously an issue between JavaScript and ADSI - JavaScript can't pass parameters to the Filter attribute properly.

you know any JavaScript nutcases who can shed light on this?
0
 
LVL 9

Accepted Solution

by:
schmiegu earned 200 total points
ID: 7298119
Besides the infos from msdn.microsoft.com IMO the best site for scripting is:
http://cwashington.netreach.net

Other links I've bookmarked, but don't find so helpful:
http://home.att.net/~wshvbs/
http://desktopengineer.com/
0
 
LVL 3

Author Comment

by:klalakomacoi
ID: 7332332
well i guess thats the best we're going to get on this so i'll close the question and give schmeigu the points.  If i ever get any answer on how to do this in js i'll forward it on.

Schmiegu, post a comment at Q_20319811 and Q_20319810 to clean up the 40 available that side.

Regards and thanks for your help
0
 

Expert Comment

by:KarelK
ID: 12295464
Array("User") in WBScript != new Array("User") in JavaScript. In JavaScript is Array an object.
0
 

Expert Comment

by:EnterpriseAutomater
ID: 23940696
but you can convert a javascript array to a vbscript SAFEARRAY if you cheat and use the scripting.dictionary object..

I've tested this process with filtering for computers and users through GetObject("WinNT://<domain>") and it works exactly as expected -- though there are a few more hoops..



function JS2VBArray( objJSArray )

{

    var dictionary = new ActiveXObject( "Scripting.Dictionary" );

    for ( var i = 0; i < objJSArray.length; i++ )

    {

        dictionary.add( i, objJSArray[ i ] );

    }
 

    return dictionary.Items();

}

var myDomains, myDom;

var myUsers, myComp,myResults;
 

// Substitue <domain> with the netbios name of your domain;

myResults = GetObject("WinNT://<domain>");
 

myResults.Filter = JS2VBArray(new Array("Computer"));
 

//This line below creates a filter on two classes

//myResults.Filter = JS2VBArray(new Array("Computer,User"));
 

var e = new Enumerator(myResults);

for (; !e.atEnd();e.moveNext())

{

	myUser = e.item();

	WScript.StdOut.WriteLine(myUser.Name + ":\t" + myUser.Class);

	//oFile.WriteLine(myUser.Name + "," + myUser.FullName)

}

Open in new window

0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now