Skip to main content
16-Pearl
October 16, 2025
Solved

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

  • October 16, 2025
  • 1 reply
  • 996 views

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!

Best answer by nmutter

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.

1 reply

nmutter16-PearlAnswer
16-Pearl
October 16, 2025

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.

MA873117416-PearlAuthor
16-Pearl
October 16, 2025

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? 

16-Pearl
October 16, 2025

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