Get-RDMSession - multiple sessions with same name

Get-RDMSession - multiple sessions with same name

avatar

I'm working on a POC utilizing CyberArk with alternate shell. What I want to do is create a new vault, clone all our RDP sessions from our default vault to the new one and test. I would do it like this (psuedocode)

Get All RDM Sessions that are RDPConfigured and loop
  - clone the session to a new var i.e. $newsession
  - set $newsession host, alternate shell, and credentials appropriately
  - change to new vault with Set-RDMCurrentVault
  - Set-RDMSession $newsession (copyes it to the new vault)

My problem is that I can't just do this $newsession = Get-RDMSession $oldsession because Get-RDMSession doesn't accept an object as parameter.
If I do $newsession = Get-RDMSession $oldsession.Name I end up with an issue when I have multiple sessions with the same name (it happens, I know it shouldn't but it does) and I'd like to avoid having to loop through in this instance to keep my code clean.

Is there a way to do a Get-RDMSession on just an ID or something that would be unique?

All Comments (16)

avatar

Hi,

I think what you are looking for is Copy-RDMSession.
$newsession = Copy-RDMSession $oldsession

Rest of your script should stay the same.
Let me know if that does the trick.

Regards

Jonathan Lafontaine

avatar

Thanks Jonathan. How I didn't even see this cmd is beyond me. I'll attribute it to being a Friday lol. I'll give this a go and report back.

avatar

So that's working great. One thing I'm trying to do is if credentials aren't set to "My Personal Credentials", I want to leave the session alone and just straight up copy instead of setting alternate shell, etc.

I can look at $oldsession.credentials but I don't see a way to determine if a credential is my personal credentials or selected from a vault of pre-set credentials. Any ideas?

avatar

Entries with credentials pointing to a "my personal credential" will have their CredentialConnectionID set to '245A4245-48E7-4DF5-9C4C-11861D8E1F81'

Jonathan Lafontaine

avatar

Thank you. In my case, personal credential GUID is actually 9F3C3BCF-068A-4927-B996-CA52154CAE3B.I will leverage that, thank you.

avatar

CredentialConnectionID would still be set to '245A4245-48E7-4DF5-9C4C-11861D8E1F81'.
PersonalConnectionID should point to your actual personal credential id '9F3C3BCF-068A-4927-B996-CA52154CAE3B'

Jonathan Lafontaine

avatar

Gotcha. Thank you!

avatar

Ok last one, I swear. If I'm doing the Copy-RDMSession and the existing folder is nested (so $oldsession.Group = "Servers\Location A\Services"), If that doesn't exist in the new vault, I get a "Connection has invalid group specified".

I can't manually create it without the folders existing to begin with, correct? I'd have to loop through and create the folders prior to setting the session?

avatar

If you want the same folder structure, I'm afraid you'll need to copy the folders first, yes.
If you don't, simply set the group to an empty string and it will appear at the vault's root.

Jonathan Lafontaine

avatar

Yeah that's what I figured but I'm hitting a weird roadblock. For example

$newfolder = New-RDMSession -type Group -Name "Hotel Servers" 
Set-RDMSession $newfolder #creates a folder at root called "Hotel Servers"
$newfolder = New-RDMSession -type Group -Name "Site A" -Group "Hotel Servers" #i want this to be created under Hotel Servers folder
Set-RDMSession $newfolder #fails with "invalid group specified"

$newfolder = New-RDMSession -type Group -Name "Hotel Servers\Site A" 
Set-RDMSession $newfolder #I want this to be created under Hotel Servers folder and this does it but I end up with a structure "Hotel Servers" -> "Hotel Servers\Site A"

Am I just doing this wrong?



avatar

You're almost there and I know it's not super intuitive but the group name has to have the new folder's name in it.
$newfolder = New-RDMSession -type Group -Name "Site A" -Group "Hotel Servers\Site A"

Jonathan Lafontaine

avatar

OK I can see the light at the end of the tunnel but here's what I do

New-RDMSession -type Group -Name "Hotel Servers" |Set-RDMSession #great, works and creates at root
New-RDMSession -type Group -Name "Site A" -group "Hotel Servers\Site A" | Set-RDMSession #fails with Connection has invalid group specified


I can see the "Hotel Servers" folder at root when I look in RDM but just not sure why the subfolder creation fails. Seems that it should work based on your post.

avatar

OK I found something. If I do an Update-RDMUI between each call, it seems to work.

avatar

Oh, yes, that.

To improve performance when batching modifications, we don't refresh the backend's data automatically.
To do so, you can either call Refresh-RDMUI as needed or add -Refresh to Set-RDMSession.

Jonathan Lafontaine

avatar

Perfect. It def slows down but that's not a big deal for this. Thank you very much for all the help.

avatar

My pleasure!

Jonathan Lafontaine