Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Exporting full list of members of a group (including groups andexternal accounts), but filtered and sorted

Reply
 
Old 10-01-2008   #1 (permalink)
Ruok


 
 

Exporting full list of members of a group (including groups andexternal accounts), but filtered and sorted

Hi,

I'm new to scripting, and I'm looking for the following:

1. How to save the output of Echo to a file (within the same script -
I don't want to use cScript batch scriptiong command).
2. List all the members of a group (including other grups and single
user names like service accounts).
3. Filter the rusults so I don't get DN (CN=...,OU=...,DC=...) - just
the user name like it is displayed in AD.
4. Display exteranal users as names not as SID's.
5. Display the name as "John Rambo", not as "Rambo, John" (that's how
my AD dispalys, and it's annoying).
5. Have the script ask me where I want to save it and with what name.

So far I found a few scripts that perform some of those functions, but
I don't know how to combine them. None of the scripts I found performs
SID transaltion for external accounts (AD does, so the information is
there), or sort the username as FirstName LastName (John Rambo).

I have used the following:

http://www.microsoft.com/technet/scr...4/hey0817.mspx
http://www.microsoft.com/technet/scr....mspx?mfr=true
and others.

Using LDIFDE and CSVDE also proves to be a pain in the neck, so a VBS
script would be ideal.

Example:

-------------------
On Error Resume Next

Set objGroup = GetObject _
("LDAP://cn=Administrators,CN=BuiltIn,...,dc=uk")
objGroup.GetInfo

arrMemberOf = objGroup.GetEx("member")

WScript.Echo "Members:"
For Each strMember in arrMemberOf
WScript.echo strMember
Next
---------------------

But this does not write it to a file, does not translate foreign
SID's, or filters etc.


This one below is the best; it lists all members and filters the info
to user name, asks you where to save it (GREAT), but does not
translate SID's or sorts it as "John Rambo". Can anyone improve it?

---------------------


Dim arrNames()
intSize = 0


Set objFSO = CreateObject("Scripting.FileSystemObject")
strfilepath = inputbox( "Please Enter Path and File Name. The output
is in xls Format.", "Input" )

Set objTextFile = objFSO.CreateTextFile(strfilepath & ".xls", True)

Set objGroup = GetObject("LDAP://
cn=Administrators,CN=BuiltIn,...,dc=uk")

For Each strUser in objGroup.Member
Set objUser = GetObject("LDAP://" & strUser)
ReDim Preserve arrNames(intSize)
arrNames(intSize) = objUser.CN
intSize = intSize + 1
Next

For i = (UBound(arrNames) - 1) to 0 Step -1
For j= 0 to i
If UCase(arrNames(j)) > UCase(arrNames(j+1)) Then
strHolder = arrNames(j+1)
arrNames(j+1) = arrNames(j)
arrNames(j) = strHolder
End If
Next
Next

For Each strName in arrNames
objTextFile.WriteLine strName
Next

WScript.Echo "This Script is now complete"
-------------------------

One problem I'm having with this one is that it does not want to work
with Domain Admin group, but exports Administrators group ok. I
checked DN (I took it from another script that works for Domain
Admins), and I do not use line wrap in Notepad. What do I do wrong?


I can see that many people are looking for this, so you will save a
lot of trouble around the world if you improve the script above. Can
we make it ask what attributes we want listed as well?

Thank you for your help.

Kamil

....................................................


My System SpecsSystem Spec
Old 10-01-2008   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: Exporting full list of members of a group (including groups and external accounts), but filtered and sorted


"Ruok" <KamilWawrzyszko@xxxxxx> wrote in message
news:8c7ec286-dcff-410b-879f-4c1ac3d080bd@xxxxxx
Quote:

> Hi,
>
> I'm new to scripting, and I'm looking for the following:
>
> 1. How to save the output of Echo to a file (within the same script -
> I don't want to use cScript batch scriptiong command).
> 2. List all the members of a group (including other grups and single
> user names like service accounts).
> 3. Filter the rusults so I don't get DN (CN=...,OU=...,DC=...) - just
> the user name like it is displayed in AD.
> 4. Display exteranal users as names not as SID's.
> 5. Display the name as "John Rambo", not as "Rambo, John" (that's how
> my AD dispalys, and it's annoying).
> 5. Have the script ask me where I want to save it and with what name.
>
> So far I found a few scripts that perform some of those functions, but
> I don't know how to combine them. None of the scripts I found performs
> SID transaltion for external accounts (AD does, so the information is
> there), or sort the username as FirstName LastName (John Rambo).
>
> I have used the following:
>
> http://www.microsoft.com/technet/scr...4/hey0817.mspx
> http://www.microsoft.com/technet/scr....mspx?mfr=true
> and others.
>
> Using LDIFDE and CSVDE also proves to be a pain in the neck, so a VBS
> script would be ideal.
>
> Example:
>
> -------------------
> On Error Resume Next
>
> Set objGroup = GetObject _
> ("LDAP://cn=Administrators,CN=BuiltIn,...,dc=uk")
> objGroup.GetInfo
>
> arrMemberOf = objGroup.GetEx("member")
>
> WScript.Echo "Members:"
> For Each strMember in arrMemberOf
> WScript.echo strMember
> Next
> ---------------------
>
> But this does not write it to a file, does not translate foreign
> SID's, or filters etc.
>
>
> This one below is the best; it lists all members and filters the info
> to user name, asks you where to save it (GREAT), but does not
> translate SID's or sorts it as "John Rambo". Can anyone improve it?
>
> ---------------------
>
>
> Dim arrNames()
> intSize = 0
>
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> strfilepath = inputbox( "Please Enter Path and File Name. The output
> is in xls Format.", "Input" )
>
> Set objTextFile = objFSO.CreateTextFile(strfilepath & ".xls", True)
>
> Set objGroup = GetObject("LDAP://
> cn=Administrators,CN=BuiltIn,...,dc=uk")
>
> For Each strUser in objGroup.Member
> Set objUser = GetObject("LDAP://" & strUser)
> ReDim Preserve arrNames(intSize)
> arrNames(intSize) = objUser.CN
> intSize = intSize + 1
> Next
>
> For i = (UBound(arrNames) - 1) to 0 Step -1
> For j= 0 to i
> If UCase(arrNames(j)) > UCase(arrNames(j+1)) Then
> strHolder = arrNames(j+1)
> arrNames(j+1) = arrNames(j)
> arrNames(j) = strHolder
> End If
> Next
> Next
>
> For Each strName in arrNames
> objTextFile.WriteLine strName
> Next
>
> WScript.Echo "This Script is now complete"
> -------------------------
>
> One problem I'm having with this one is that it does not want to work
> with Domain Admin group, but exports Administrators group ok. I
> checked DN (I took it from another script that works for Domain
> Admins), and I do not use line wrap in Notepad. What do I do wrong?
>
>
> I can see that many people are looking for this, so you will save a
> lot of trouble around the world if you improve the script above. Can
> we make it ask what attributes we want listed as well?
>
> Thank you for your help.
>
> Kamil
>
> ...................................................
>
A few points. The member attribute of groups never includes any objects that
have the group designated as their "primary" group. The same is true of the
memberOf attribute of users, the Members method of groups, etc. If all users
have "Domain Users" designated as their "primary" group, the group will
always appear to be empty, unless you use other methods. However, no one
should have "Domain Admins" designated as their "primary". Either you meant
"Domain Users", or you have changed the "primary" group of all members of
"Domain Admins", which makes little sense.

Attempting to parse the Common Name of users so "Rambo, John" becomes "John
Rambo" might be done as follows:

strName = objUser.cn
intComma = InStr(strName)
strLast = Left(strName, intComma - 1)
strFirst = Trim(Mid(strName, intComma + 1))
strName = strFirst & " " & strLast

However, this may not give the results you want in all cases. You don't say,
but I assume you are only interested in direct members of the group, not
members due to group nesting.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 10-06-2008   #3 (permalink)
Ruok


 
 

Re: Exporting full list of members of a group (including groups andexternal accounts), but filtered and sorted

Hi Richard,

Thank you for your reply. All users are set with "Domain Users" as
their primary groups. I failed to specify that I get the error message
in the script:

-------------------------------------
Script: C:\Scripts\Write DomainAdmins to a file.vbs
Line: 12
Char: 5
Error: 0x80005000
Code: 80005000
Source: (null)
-------------------------------------

And the output file is empty. Line 12 seems to be:

Set objUser = GetObject("LDAP://" & strUser)

But I copied the whole script and only changed the line with DN, which
I copied it from another similar script, which works ok. I tried a few
times, and I made sure that line wrapping is not the issue. What else
can I check? To remind you, it works ok with Administrators group, but
not Domain Admins:

Set objGroup = GetObject("LDAP://
cn=Administrators,CN=BuiltIn,dc=......,dc=uk")
Set objGroup = GetObject("LDAP://cn=Domain Admins,ou=Global
Groups,OU=Groups,dc=.....,dc=uk")

However, the following script works ok:

-------------------------------------------
On Error Resume Next

Set objGroup = GetObject _
("LDAP://cn=Domain Admins,ou=Global
Groups,OU=Groups,dc=smh,dc=......,dc=uk")
objGroup.GetInfo

arrMemberOf = objGroup.GetEx("member")

WScript.Echo "Members:"
For Each strMember in arrMemberOf
WScript.echo strMember
Next
--------------------------------------

Any ideas would be appreciated.


Regarding the script you provided for sorting/swapping places of First
Name and Last Name, when I paste it in line 11, I get this error
message:

---------------------------
Script: C:\Scripts\Write Administrators members to a file .vbs
Line: 11
Char: 1
Error: Object required: 'objUser'
Code: 800A01A8
Source: Microsoft VBScript runtime error
---------------------------

When I paste it in line 19 (or 29), I get this:

---------------------------
Script: C:\Scripts\Write Administrators members to a file .vbs
Line: 19
Char: 1
Error: Wrong number of arguments or invalid property assignment:
'InStr'
Code: 800A01C2
Source: Microsoft VBScript runtime error
---------------------------


I only need direct members of a group, ideally with foreign SID’s
translated to names. Also, is there a way/tool/command, with which I
can get easily DN of a group/person so that I can copy it and paste
into a script? I failed to find a straightforward solution on the Net
so far.

Once again, thank you for all the input.

Regards

Kamil


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
List everyone group members ? VB Script
list users, NOT members of a group PowerShell
Finding members of RDP groups of a list of computers VB Script
Why this script list a local administrator group members? PowerShell
How to create a list with all distrubtion groups and it's members PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46