Is it possible to use Credential Repository values in a PowerShell Script?
I have a PowerShell script that will:
This works with the necessary login credentials hard-coded into the script. The script is entered as an Embedded Script in Remote Desktop Manager as a PowerShell Session entry and can be executed from Remote Desktop Manager.
I also have a Credential Username/Password entry that holds the credentials for logging in to the LogMeIn Central web portal.
I'd like to alter the script so that it can pull the username and password from the credentials entry.
Can a PowerShell Session entry access the Credentials Repository holding the username and password?
If so... how do you reference those values in the PowerShell embedded script?
Jamie
Hello,
It is possible to get the credential entry inside your PowerShell script. First of all, you need to enable the Load RDM Cmdlet option in order to have access to all RDM cmdlets from the RDM PowerShell module.
Then, you need to add these lines to fetch the entry and extract the username and password. Please replace CredentialEntryName on the first line with the name of your credential entry .$session = Get-RDMSession -Name "CredentialEntryName"$username = $session.HostUserName$passwd = Get-RDMSessionPassword -AsPlainText -Session $session
Best regards,
Érica Poirier
Érica,
That worked perfectly for what I was attempting to do. The help is greatly appreciated.
Is there a resource for RDM / PowerShell that I should be looking at for information like this? I was searching but obviously I didn't find what I was looking for. :)
Again, thanks so much for the help.
Jamie
Hello,
You will find all available RDM PowerShell cmdlets on the RDM online help page.
https://help.remotedesktopmanager.com/powershell_cmdlets.htm
And you can consult the PowerShell section of our forum to get some script samples and tricks.
https://forum.devolutions.net/forum42-remote-desktop-manager--powershell-repository.aspx
Best regards,
Érica Poirier
OK, I will be sure to consult those resources. Thanks again.
Take care.
Jamie
So now I've run into another little question.
The first Credential Repository "Portal Credentials" worked fine and I was able to pull the user / pass from the session object accessed with Get-RDMSession just as you suggested.
However, I have another Credential Repository "LogMeIn Credentials" that I'm trying to access the same way, but I get an error stating:
"Get-RDMSession: Cannot validate argument on parameter 'Name'. The argument "LogMeIn Credentials" does not belong to the set..." and it proceeds to list all of the sessions it does find.
The two credential entries appear to be of the same type and have the same security settings. What am I missing that would cause Get-RDMSession to not be able to access one but not the other?
Jamie
Hello,
This error explains that the entry with the name "LogMeIn Credentials" doesn't exist in the entry list. When you use the Name parameter with the Get-RDMSession cmdlet, you must be sure to have the exact same name (spaces, case letters, special characters, etc).
Best regards,
Érica Poirier
That's what I thought... and I went over that name multiple times and still was getting the error message. This morning, after reading your reply, I just ran
Get-RDMSession -Name 'LogMeIn Credentials'
from the PowerShell RDM CmdLet but I copy/pasted the name right out of RDM... and of course, it worked. :)
So I'm feeling foolish... and I'm going to write it off as being "end of the day tiredness" and I should have walked away to get some fresh eyes.
Thank you very much.
Jamie
It would appear that if the credential entry is the child of a secure note, then it is not seen by Get-RDMSession.
Is this by design? Am I overlooking something in the security or is this just the nature of the Note / Secure Note type? At least I now know I'm not totally losing it.
Just for informational purposes there also seems to be some delay involved here.
A credential entry created a few days ago in a plain folder is seen by Get-RDMSession every time I test it.
I just made two new credential entries in the same folder (one type username/password and one as type custom). If you immediately try Get-RDMSession on the new entries they fail. Repeatedly. After waiting a few minutes both will eventually return Name, Group, ID.
So there seems to be some type of sync issue or delay with the cloud database?
Hello,
The children of an entry are called SubConnections and each parent entry has a SubConnections property that contains an array of PSConnection objects. Extract the PSConnection you want to access and put it into a variable. Then use the same cmdlets to get the username and password with that new object.
Here is a sample script :$parent = Get-RDMSession -Name "MyParentEntry"$child = $parent.SubConnections | where {$_.Name -eq "MyChild"}$username = Get-RDMSessionUserName -Session $child$password = Get-RDMSessionPassword -Session $child -AsPlainText
Best regards,
Érica Poirier
Hello,
About the delay, it's in fact the cache file that is not updated. You need to use the Update-RDMUI cmdlet to update the cache file in PowerShell to get all recent modifications to your entries.
Best regards,
Érica Poirier
Makes complete sense. Thanks for straightening me out... again. ;) I'll put this to good use.
Érica, have a terrific weekend.
Hello,
Thanks for your feedback!
Have a great weekend too, Jamie :D
Best regards,
Érica Poirier