Skip to main content
Oct 16, 2025 6:46 AM UTC
Solved

How to Get All Users from a Specific User Group in ThingWorx?

Hi everyone ,

   I’ve been working with user management in ThingWorx and came across a related use case to this post 

 

https://community.ptc.com/t5/ThingWorx-Developers/How-to-Find-all-User-Groups-for-a-Given-User/m-p/1038382#M70705

 

about getting all user groups for a given user (using Users[principal].GetGroups()).

 

Now I want to do the reverse:

Get all users that belong to a specific User Group? is it possible? 

 

Thanks in advance for your insights!

nmutterAnswer
Oct 16, 2025 9:07 AM UTC

you can get the direct members of a usergroup like

let result = Groups["Administrators"].GetGroupMembers();

result e.g.

- "Administrator" - type User

- "SomeOtherGroup" - type Group

This will also include contained groups (indicated in the result in the "type" column - group or user). To get also indirect members you would need to iterate over the contained groups and get all members, and repeat. But watch out as TWX groups can create a loop which you must detect and stop iterating a 2nd time.

5 replies

nmutterAnswer
Oct 16, 2025 9:07 AM UTC

you can get the direct members of a usergroup like

let result = Groups["Administrators"].GetGroupMembers();

result e.g.

- "Administrator" - type User

- "SomeOtherGroup" - type Group

This will also include contained groups (indicated in the result in the "type" column - group or user). To get also indirect members you would need to iterate over the contained groups and get all members, and repeat. But watch out as TWX groups can create a loop which you must detect and stop iterating a 2nd time.

MA8731174Author
Oct 16, 2025 10:24 AM UTC

Thank you! do you also have any clue that if there exists also a function with which we can remove all the users which one group has in it? 

Oct 16, 2025 12:06 PM UTC

I am not aware of such a service. Only deleting members one by one via the DeleteMember service