List users from all Local groups on a windows server

(imported topic written by Lalitha91)

Q: names of local groups => lists all local groups on the server

Q: members of local groups => lists all users from all local groups

Is there a way to combine the above 2 relevances such that I can associate which users belong to which local groups ?

I do not want to use the below relevance as I have to specify each Local group …

Q: members of local group “Administrators”

I would appreciate if someone can help me with this … need to provide a report for Audit …

Thanks

(imported comment written by Lee Wei)

Hi Lalitha,

Here are a few different forms that you might be able to use.

If a group does not have any members, it will not be listed

q: (name of it, members of it) of local groups
A: Administrators, TRADERS\leewei
A: Administrators, TRADERS\Administrator
A: Guests, TRADERS\Guest
A: Users, NT AUTHORITY\INTERACTIVE
A: Users, NT AUTHORITY\Authenticated Users
A: Users, TRADERS\Administrator
A: Users, TRADERS\Standard User
A: Debugger Users, TRADERS\leewei

This one concatenates the members together.

“%0A%0D” is carriage return and linefeed. It should cause the results to be placed on different lines in the console

q: (name of it, concatenations “%0A%0D” of (members of it as string)) of local groups whose (number of members of it > 0)
A: Administrators, TRADERS\leewei%0a%0dTRADERS\Administrator
A: Guests, TRADERS\Guest
A: Users, NT AUTHORITY\INTERACTIVE%0a%0dNT AUTHORITY\Authenticated Users%0a%0dTRADERS\Administrator%0a%0dTRADERS\Standard User
A: Debugger Users, TRADERS\leewei

Another form that might be useful if you need to show all groups, even if no members

q: (name of it, (if (number of members of it > 0) then (concatenations “%0A%0D” of (members of it as string)) else (“No Members”)) ) of local groups
A: Administrators, TRADERS\leewei%0a%0dTRADERS\Administrator
A: Backup Operators, No Members
A: Cryptographic Operators, No Members
A: Distributed COM Users, No Members
A: Event Log Readers, No Members
A: Guests, TRADERS\Guest
A: IIS_IUSRS, No Members
A: Network Configuration Operators, No Members
A: Performance Log Users, No Members
A: Performance Monitor Users, No Members
A: Power Users, No Members
A: Remote Desktop Users, No Members
A: Replicator, No Members
A: Users, NT AUTHORITY\INTERACTIVE%0a%0dNT AUTHORITY\Authenticated Users%0a%0dTRADERS\Administrator%0a%0dTRADERS\Standard User
A: Debugger Users, TRADERS\leewei

Lee Wei

(imported comment written by MattBoyd)

Here’s one way:

(name of it & “:” & concatenation "; " of (members of it as string)) of local groups

Edit: It looks like Lee beat me to posting an answer, and his examples are much better.

(imported comment written by Lalitha91)

Thank You Lee Wei and boyd for your responses. That was helpful …

I tried Lee’s 3rd method hoping, the users will be placed on different lines …however, it just put a space between the users belonging to an account.

I combined boyd & Lee’s 3rd method so I could replace the space with ; for better viewing though would like it to go different lines …

(name of it & “:” & concatenation of ((if (number of members of it > 0) then (concatenations “;” of (members of it as string)) else (“No Members”)))) of local groups

Thanks

(imported comment written by Lalitha91)

Basically, I would like to see the data in the following format :

A: Administrators:TRADERS\leewei

A: Administrators:TRADERS\Administrator

A: Backup Operators:No Members

A: Guests:TRADERS\Guest

A: Users:NT AUTHORITY\INTERACTIVE

A: Users:NT AUTHORITY\Authenticated Users

A: Users:TRADERS\Administrator

A: Event Log Readers:No Members

A: Guests:TRADERS\Guest

Thanks …

Also, can you tell me if the relevance I tried is right or have I complicated?

(imported comment written by Lee Wei)

This will give you the output that you want.

(item 0 of it & “:” & item 1 of it as string) of (name of it, (if (number of members of it > 0) then (members of it as string) else (“No Members”))) of local groups

(imported comment written by Lalitha91)

Thank You!!

(imported comment written by var91)

hi,

(item 0 of it & “:” & item 1 of it as string) of (name of it, (if (number of members of it > 0) then (members of it as string) else (“No Members”))) of local groups

Result:

Administrators:hostname\administrator

Administrators:hostname\admin

Administrators:hostname\Domain-Admins

This works very fine.

Is it possible to exclude for example the local User “admin”, that it isn’t in the report?

Thanks for help

Andi

(imported comment written by Lee Wei)

You can try this:

(if (it does not contain (":" & computer name & “\admin”)) then (it) else (nothing)) of (item 0 of it & “:” & item 1 of it as string) of (name of it, (if (number of members of it > 0) then (members of it as string) else (“No Members”))) of local groups

(imported comment written by jschuldiner91)

I am trying to do the same thing only I would like to have a report that excludes multiple users

(if (it does not contain (":" & computer name & “\admin”)) then (it) else (nothing)) of (item 0 of it & “:” & item 1 of it as string) of (name of it, (if (number of members of it > 0) then (members of it as string) else (“No Members”))) of local groups

Is it possible to exclude multiple local Users for example “admin”, “administrator†and “domain name\Domain Admins” that it isn’t in the report?

(imported comment written by Lee Wei)

You can try expanding the AND clause and continue to add additional filtering criteria.

(if (it does not contain (":" & computer name & “\admin”)

color=red

and it as lowercase does not contain (":" & computer name as lowercase & “\administrator”)[/color] ) then (it) else (nothing)) of (item 0 of it & “:” & item 1 of it as string) of (name of it, (if (number of members of it > 0) then (members of it as string) else (“No Members”))) of local groups