Import script - Create a credential, then a folder object from a template and link credential plus add hostname and IP to folder

Import script - Create a credential, then a folder object from a template and link credential plus add hostname and IP to folder

avatar

Hi,

I have a simple script that I'm building upon more detail. I need help linking the credential and adding the additional data to the folder object.
My RDM structure follows the following sample:

Main folder \

Folder object type1\

Folder object1\

object1

object2

object3

Folder object2\

object1

object2

Folder object type2\


For example, I would have a path like this:

Acme Inc\Client assets\VMwareHost1\

and this path would have 3 objects http VMwareHost1, ssh VMwareHost1 and winscp VMwareHost1

The three objects in my example above inherit credentials from the VMwareHost1 parent folder, as well as the Host name and IP. They use variables $COMPUTER_HOST$ (object name), $COMPUTER_IP$ (for web/ssh/winscp parameters), $USERNAME$ and $PASSWORD$ for parameter credentials passed on to local tools or via Devolutions Web Login.

I have an RDM template of the Folder object containing the tree connection objects.

A sample import string would look like:

Name,Hostname,IP,username,password,description

VMware server,VMwareHost5,192.168.1.33,root,monkey123,in datacenter 5; rack 21; row 15/Dell ST: ABC123456


Test code:

 1 Import-Module "${env:ProgramFiles(x86)}\Devolutions\Remote Desktop Manager\RemoteDesktopManager.PowerShellModule.psd1" 
 2
 3 $creds =New-RDMSession -Name "VMware server root" -Type Credential -Group "Acme Inc\Credentials\Vendors" 
 4 $creds.Credentials.UserName="root" 
 5 Set-RDMSession $creds -Refresh 
 6 Set-RDMSessionPassword -ID $creds.ID -Password (ConvertTo-SecureString "monkey123" -AsPlainText -Force) 
 7 $group-templ = New-RDMSession -Name "VMwareHost5" -Type TemplateGroup -TemplateID "12345678-9012-1234-5678-901234567890" -Group "Acme Inc\Client assets\VMwareHost5\" 
 8 $group-templ.CredentialConnectionID = $creds.ID
 9 $group-templ.IP = "192.168.1.33"
10 $group-templ.Host = "VMwareHost5"
11 $group-templ.Name = "VMwareHost5"
12 $group-templ.Description = "in datacenter 5; rack 21; row 15/Dell ST: ABC123456"
13 Set-RDMSession $group-templ–Refresh
  • Set-RDMSession $website –Refresh


Failing lines:

 8 $group-templ.CredentialConnectionID = $creds.ID
 9 $group-templ.IP = "192.168.1.33"

I need help executing correctly the above two lines against the folder object (created at line 7).

Thanks in advance!

-MA
PS. I'm running RDM 2021.1.25.0 with a SQL database

All Comments (11)

avatar

Hello,

Thank you for reaching out to Devolutions support. Could you please confirm the error you are getting or better yet take a screenshot if possible ?

Best regards,

Eric St-Martin

avatar

Eric,

Here are the errors:
forum image

Thanks,

MA

avatar

Hello,

Ok I am getting the same error as you. When you are calling the:

$website = New-RDMSession -Name "Test-website-55" -Type TemplateGroup -TemplateID "31fe93c9-248c-4362-9f30-d1b3f1b8f757" -Group "Acme Inc\Client assets\VMwareHost1\"


What type of session are you trying to create exactly?

The TemplateGroup you are calling has the structure you mentioned above? VMwareHost1 (folder) with the 3 objects http VMwareHost1, ssh VMwareHost1 and winscp VMwareHost1

Best regards,

Eric St-Martin

avatar

It's a server-type folder object.
Yes, the template has the server-folder object at the top, and the connection objects in it.
My code only fails when trying to add the credentials, Host and IP. Name and Description work fine.

MA

avatar

Hello,

Ok I see the issue. The information on the folder is grouped differently then on a Session. So in this case on the folder if you want to change the IP or Host you would need to call:

$website.MetaInformation.IP = "IP"
$website.MetaInformation.MachineName = "Hostname"
$website.GroupDetails.Username = "Username"
$website.GroupDetails.SafePassword = "Password"


This information on a folder is like the below;
    <ConnectionType>Group</ConnectionType>
    <Description>Here is my description</Description>
    <Group>VMwareHost1</Group>
    <Name>VMwareHost1</Name>
    <UpdateDateTime>2021-05-18T20:23:50</UpdateDateTime>
    <GroupDetails>
      <SafePassword>/UvZdaz1yMA=</SafePassword>
      <UserName>Username</UserName>
    </GroupDetails>
    <MetaInformation>
      <IP>15464</IP>
      <MachineName>Adfg</MachineName>
    </MetaInformation>

You can get this via right-clicking on your session or folder and select Clipboard – Copy from here you can either paste in a text editor or use the Preview tab to view the XML.

Best regards,

Eric St-Martin

avatar

Adding MetaInformation does not work with IP or MachineName. Same error:
forum image

With regards to credentials. I'd like to link to a credentials object not to add them into the object.

MA

avatar

I manually created my server-type object and noticed I get a different set of XML tags. I do not have "MetaInformation". The equivalent for the section for me is "GroupDetails" only with the Host and IP blocks. Since I'm not using embedded username/password those fields are missing as expected. See below:

<ConnectionType>Group</ConnectionType>
<CredentialConnectionID>6923dc9b-00d0-4125-853c-c6886561b3e9</CredentialConnectionID>
<CredentialConnectionSavedPath>Acme Inc\Client assets\VMware server</CredentialConnectionSavedPath>
<Description>in datacenter 5; rack 21; row 15/Dell ST: ABC123456</Description>
<Group>VMwareHost1</Group>
<Name>VMwareHost1</Name>
<UpdateDateTime>2021-05-19T00:25:46</UpdateDateTime>
<GroupDetails>
<GroupType>Server</GroupType>
<Host>VMwareHost1</Host>
<IP>192.168.1.33</IP>
</GroupDetails>

I noticed the extra block "MetaInformation" appear when I populated the Host and IP under the Asset information. This is not what I'm looking for. I need the Host and IP from the General tab.

Thanks,

MA

avatar

Hello,

Just wanted to confirm that with the information you found it is working or not ?

Are you still getting errors when running your script ?

Best regards,

Eric St-Martin

avatar

Eric,

I was told that given the nature of my template (multi-object), I had to do a Get-RDMSession command to get that folder-object and then try to add the data to it. I still cannot add the IP to the General tab. Below is the updated code.

*** Additionally, I'm unable to run the code in one shot. I have separated the segments with blank rows (5 & 9) below to show how I'm running it to run successfully.

 1 Import-Module "${env:ProgramFiles(x86)}\Devolutions\Remote Desktop Manager\RemoteDesktopManager.PowerShellModule.psd1" 
 2 $creds =New-RDMSession -Name "VMware server root" -Type Credential -Group "Acme Inc\Credentials\Vendors" 
 3 $creds.Credentials.UserName="root" 
 4 Set-RDMSession $creds
 5
 6 Set-RDMSessionPassword -ID $creds.ID -Password (ConvertTo-SecureString "monkey123" -AsPlainText -Force) 
 7 $group-templ = New-RDMSession -Name "VMwareHost5" -Type TemplateGroup -TemplateID "be661754-5b8c-4562-a689-627add40e55e" -Group "Acme Inc\Client assets\VMwareHost5\" 
 8 Set-RDMSession $group-templ
 9 
10 $group-obj = Get-RDMSession | where {$_.name -eq "VMwareHost5"}
11 $group-obj.CredentialConnectionID = $creds.ID 
12 $group-obj.Host ="VMwareHost5"
13 $group-obj.HostDetails.IP ="192.168.1.33"
14 $group-obj.Description = "in datacenter 5; rack 21; row 15/Dell ST: ABC123456"
15 Set-RDMSession $group-obj –Refresh


$group-obj.IP = "192.168.1.33" reports an invalid "IP" parameter.
Note I removed the "-Refresh" in lines 4 and 8 in an effort to expedite processing.

  1. What is the correct field to populate the IP under the General tab?
  2. What do you recommend to implement in a script where the code needs to run all at once?


-MA

avatar

Mario,

I tested the following on my end. Let me know if this makes sense for what you are trying to do. I am able to run this in 1 line.

Import-Module "${env:ProgramFiles(x86)}\Devolutions\Remote Desktop Manager\RemoteDesktopManager.PowerShellModule.psd1" 
$creds =New-RDMSession -Name "VMware server root" -Type Credential -Group "Acme Inc\Credentials\Vendors" 
$creds.Credentials.UserName="root" 
Set-RDMSession $creds -refresh
Set-RDMSessionPassword -ID $creds.ID -Password (ConvertTo-SecureString "monkey123" -AsPlainText -Force) -refresh
$grouptemp = New-RDMSession -Name "VMwareHost5" -Type TemplateGroup -TemplateID "95d5739b-2fd9-4c7b-a1e0-3152774cff98" -Group "Acme Inc\Client assets" 
Set-RDMSession $grouptemp -refresh
$groupobj = Get-RDMSession | where {$_.name -eq "VMwareHost5"}
$groupobj.CredentialConnectionID = $creds.ID 
$groupobj.GroupDetails.Host ="VMwareHost5"
$groupobj.GroupDetails.IP ="192.168.1.33"
$groupobj.Description = "in datacenter 5; rack 21; row 15/Dell ST: ABC123456"
Set-RDMSession $groupobj –Refresh



My templategroup is as follows.

Server type folder >
HTTP entry
WinSCP entry
SSH entry

Post script it looks like this:

forum image


The folder took the changes:


forum image

On the entries, I set them up via the template to do the following:

forum image
forum image
forum image


Let me know how this works for you.

Best regards,

Eric St-Martin

avatar

Eric,

I happily report your adjusted code worked beautifully and in one shot error-free.
Now I can start loading my real data from CSV and populate my structure.
Many thanks!

-MA