Retrieve users based on condition

Retrieve users based on condition

avatar

Hello Support,

I am required to get users or sessions filtered by property values other than Name. Currently, I do not see an option using the regular Get-RDMUser/Session commands. Is there any way to do it?

All Comments (7)

avatar

Hello,

You can access any fields set to the user.
In order to get the structure of a user record, I recommend using the basic Powershell instruction Select-Object

It would look like this:
$User = Get-RDMUser[0]
$User | Select-Object -Property *
# this will list all of the settings.

Then you can filter using where-object instruction, in that fashion:
$FilteredUsers = Get-RDMUser | Where-Object {$_.<the field you want to look into> -eq "<the value you're looking for>"}

I hope this helps!

Best regards,

Alex Belisle

avatar

Hi Alex,

While this does what is required, it involves significant time to fetch the data initally. So, if I rephrase, I was looking for an option to filter it while fetching from the database and not requiring to load the entire data set.

avatar

Hello

I understand very well, unfortunately I'm not aware of any workaround.
I don't know however f you're referring to my first "Get-RDMUser[0]", obviously this call is not required, simply used for finding the filed names...
Other than that, I'm afraid we have to proceed this way.

Sorry I cannot be of more help.

Best regards,

Alex Belisle

avatar

Hi Alex,

Let me explain what I was trying to achieve. It may help you suggest a better solution. I have a .NET app that needs to create/modify/delete RDM entities (session, user, permission, etc.). I had two choices to run it either with an always on powershell session with RDM or a new session each time I try to sync entities. The always on session works fine for some time (random time, sometimes as long as a day and sometimes as low as a hour) and then it stops working (requires kill and start a new one). One of the requirements I had is to modify an entity based on its value in one of the custom fields (CustomField1Title). The sync should happen in the least possible amount of time. So, if I had to start a new powershell session for each invocation, fetching all entities takes about 10 seconds, which is not allowed. Hope you may have a better option to handle this situation.

Best regards

avatar

Hello,

It is always a considerable challenge to optimize powershell script,as it depends a lot on the RDM performance itself.
What is the data source you're working with, and your RDM version?
Depending on the size (number of entries) of your vaults, it may be worth to split the entries in multiple vaults to speed up the loading time.

Thank

Alex Belisle

avatar

Hello
i do not understand...i'am sorry
for exemple if y want to delete all users begins by Yourdomain

This line give us all users with Name and ID

Get-RDMUser | Select-Object -Property Name,ID


Result :

Name                         ID                                  
----                         --                                  
YourDomain\utest0080         c6eb32cf-2250-455c-bb97-0095ee711fb4
YourDomain\utest0036         25478da5-6e60-4320-a152-03fc3f2a55e4
OTHERDOMAIN\utest0029        5366ca75-30cf-4e10-b14f-078b2acabcb6
YourDomain\utest0034         7937d1f0-f609-4636-8da1-0d742488bbd5
YourDomain\utest0045         0f848099-b9e5-4d17-9f17-0ddcc9b0beaf
DOMAINE\utest0058            bd2f1a8c-701f-49e4-96bc-0ee05d2cf18c
YourDomain\utest0025         de03460e-f230-4565-aacf-0f2265bb7306
YourDomain\utest0078         95985317-3c05-4dad-8c2f-121207062596
YourDomain\utest0076         912fdd80-5a37-4c93-9ad2-137113c89892
ABCDEFGKJH\utest0013         8c1e5682-35ec-4066-841f-17bd180fb596
YourDomain\utest0040         d1aab7ad-a385-4a91-922e-1a2488b61899
99877TVOBT\utest0035         7818e4c2-412a-4af7-a273-1cec770221dd
YourDomain\utest0101         79243c28-34ee-4307-bfa9-1d854fc58679


Now i need to filter only the users begins by "YourDomain*"

How to ?

and after, can i use Remove-RDMUsers ?

regards

avatar

Hello Vincent,

You could use the following to remove them directly:

Get-RDMUser | Where-Object {$_.name -like "YourDomain\*"} | Remove-RDMUser
Update-RDMUI


If you just want to see the result without removing them:

Get-RDMUser | Where-Object {$_.name -like "YourDomain\*"} | Select-Object -Property Name,ID 


Best regards,

Richard Boisvert