Click to See Complete Forum and Search --> : How could I exclude a member in a group ?


SherTeks
June 2nd, 2008, 06:04 AM
I am using the following script to echo all members except 'Administrator'
in 'Administrators' group :

strComputer = "XYZCOMPUTER"

Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")

For Each objUser In objGroup.Members
If objUser.Name <> "Administrator" Then
Wscript.Echo objUser.Name
End If
Next

In a list of Administrators (In XP, accessible through Right click 'My
Computer' -> Manage -> Local Users and Groups -> Groups ->
Administrators (double click)), I've few entries like :

Administrator
user1
user2
xyzdom\user3
user3
user4

The above script echoes user3 twice.

I don't want the script to echo 'user3' for the entry xyzdom\user3.

How could the condition be specified/modified in the script ?

Thanks in advance.

PeejAvery
June 2nd, 2008, 07:50 AM
Well, you could use a temporary array. Put all users encountered in there and then check that for duplicates.

However, you should be concerned more with why user3 is showing up twice. What differences are there? Are there any hidden users in the Documents & Settings folder?

SherTeks
June 2nd, 2008, 08:11 AM
'user3' doesn't show up twice automatically by the system.

I make it available by explicitly adding it to the 'Administrators' group by
clicking 'Add' tab on 'Administrators Properties' dialog and entering the
user in 'Select users, computers or groups' dialog.

'xyzdom' in xyzdom\user3 is one of the locations shown when I click on
'Locations' tab in 'Select users, computers or groups' dialog.