cancel
Showing results for 
Search instead for 
Did you mean: 

Get users in specific user groups

Joseph_Sepanek
Champ on-the-rise
Champ on-the-rise

Hi,

I get all of the user groups with this: UserGroupList userGroups = app.Core.UserAdministration.GetUserGroups();, but then I need to get the users in a specific group in userGroups.  I found this line: app.Core.UserAdministration.GetUsers(); and doing a foreach against userGroups, I can find my specific UserGroup.  I then change the line to app.Core.UserAdministration.GetUsers(usergrp);, however I can't figure out what is on the left side to actually retrieve the users.  I've found lots of examples on how to add someone to a user group, but not on getting the users in a user group via script.

Thank you.

1 ACCEPTED ANSWER

Justin_Carlson
Content Contributor
Content Contributor

@Joe Sepanek I think you are on the right track app.Core.UserAdministration.GetUsers(usergrp);. That should return all the users in the user group past in. The "left side" is that it returns a UserList object type. Which you can also loop over if you want (not sure if that is what you meant).

 

For example, if you just wanted to loop over all the User Groups and write them out along with all the Users in each group you could use this:

foreach(UserGroup usrGrp in app.Core.UserAdministration.GetUserGroups()){	Console.WriteLine($"--{usrGrp.Name}");	foreach(User usr in app.Core.UserAdministration.GetUsers(usrGrp))	{		Console.WriteLine($"----{usr.Name}");	}}

The Console.WriteLine obviously would only work in a Console app, not a script, but it illustrates using the User.

 

Not sure if that is what you were looking for.

 

If not, maybe you could describe what you are trying to do with the list of Users that are in the User Group once you get it?

View answer in original post

3 REPLIES 3

Justin_Carlson
Content Contributor
Content Contributor

@Joe Sepanek I think you are on the right track app.Core.UserAdministration.GetUsers(usergrp);. That should return all the users in the user group past in. The "left side" is that it returns a UserList object type. Which you can also loop over if you want (not sure if that is what you meant).

 

For example, if you just wanted to loop over all the User Groups and write them out along with all the Users in each group you could use this:

foreach(UserGroup usrGrp in app.Core.UserAdministration.GetUserGroups()){	Console.WriteLine($"--{usrGrp.Name}");	foreach(User usr in app.Core.UserAdministration.GetUsers(usrGrp))	{		Console.WriteLine($"----{usr.Name}");	}}

The Console.WriteLine obviously would only work in a Console app, not a script, but it illustrates using the User.

 

Not sure if that is what you were looking for.

 

If not, maybe you could describe what you are trying to do with the list of Users that are in the User Group once you get it?

Thank you!  That was what I needed.  Much appreciated!

sskupien
Community Manager
Community Manager

@Justin Carlson  Nice job!