Forum / Remote Desktop Manager - PowerShell Repository

Get-RDMSession

  • Create an Issue
  • Cancel

Hi,

Have another problem.

When i run the script below for a second time the first record is always seen as a new entry:


write-Host "in HTTP" -ForegroundColor green
write-Host "$ConnectionType $Name $Group $HostIP $Port $CredentialUserName $CredentialPassword" -ForegroundColor Green

##################################################
# Test Existing RDM Entry #
##################################################


$Session = Get-RDMSession | Where-Object {$_.Name -eq $Name -and $_.Group -eq $Group}
If ($Session) {

write-Host "Existing Record" -ForegroundColor Magenta


}

##################################################
# Create RDM Entry #
##################################################
else
{
write-host "New Record" -ForegroundColor Yellow
$Session = new-rdmsession -group $Group -host $HostIP -name $Name -setsession -TemplateID $Template -type "WebBrowser"
write-output $Session.ID
set-RDMSession $Session
Update-RDMUI
}

Clock2 yrs

Hi,

Just so we can limit the scope, could you tell us what is you RDM version?
On what Data Source Type are you working on?

There is also a little test you can perform, after you run your script once, could you check what a plain Get-RDMSession would return?

Thank you



Alex Belisle

signaturesignature

Clock2 yrs

Hi,

Im using Maria-db

RDM version 13.0.6.0

i have cleared all entries and started again. Output below:


PS C:\DataImport> .\import.ps1
in HTTP
http Draytek W G Mackay Skip Hire Ltd - Cockermouth\internet admin
New Record

Updating Record
in HTTPS
SSL Draytek Chase Hotel\internet admin
New Record
Guid
----
25ab1569-0d77-4bfb-881c-852820fcd0d0
05b9d868-de9f-4c95-bdef-d36af096f687
Updating Record
in HTTPS
SSL Draytek ABC\internet admin
New Record
0fd9a112-7aa5-4549-976a-94b14991988c
Updating Record
in HTTPS
SSL Draytek Dr\internet admin
New Record
5848b395-4ce1-48b7-a7b4-a30ecbe597a4
Updating Record


PS C:\DataImport> get-rdmsession

Name Group ID
---- ----- --
Key-ParkDean .Keys 10a46b93-52fb-471e-82d9-00baea99df03
Draytek ABC\internet 0fd9a112-7aa5-4549-976a-94b14991988c
Draytek Chase Hotel\internet 05b9d868-de9f-4c95-bdef-d36af096f687
Draytek Dr\internet 5848b395-4ce1-48b7-a7b4-a30ecbe597a4
Draytek W G Mackay Skip Hire Ltd - Cockermouth\internet 25ab1569-0d77-4bfb-881c-852820fcd0d0


PS C:\DataImport> .\import.ps1
in HTTP
http Draytek W G Mackay Skip Hire Ltd - Cockermouth\internet admin
New Record

Updating Record
in HTTPS
SSL Draytek Chase Hotel\internet admin
Existing Record
Updating Record
in HTTPS
SSL Draytek ABC\internet admin
Existing Record
Updating Record
in HTTPS
SSL Draytek Dr\internet admin
Existing Record
Updating Record
Guid
----
596c39b3-6def-492c-983c-3323028412a0


PS C:\DataImport> get-rdmsession

Name Group ID
---- ----- --
Key-ParkDean .Keys 10a46b93-52fb-471e-82d9-00baea99df03
Draytek ABC\internet 0fd9a112-7aa5-4549-976a-94b14991988c
Draytek Chase Hotel\internet 05b9d868-de9f-4c95-bdef-d36af096f687
Draytek Dr\internet 5848b395-4ce1-48b7-a7b4-a30ecbe597a4
Draytek W G Mackay Skip Hire Ltd - Cockermouth\internet 25ab1569-0d77-4bfb-881c-852820fcd0d0
Draytek W G Mackay Skip Hire Ltd - Cockermouth\internet 596c39b3-6def-492c-983c-3323028412a0

Clock2 yrs

Hello,

I understand that you sent only the part of your script that doesn't seem to be working.
When I try your piece of script in my RDM 13.0.6.0 (MariaDB Data Source), Get-RDMSession returns the right session.
Could you specify what you try to achieve?
Have you tried your script within RDM? (Tools -> Powershell (RDM CmdLet))

Thanks

Best regards,



Alex Belisle

signaturesignature

Clock2 yrs

Hi Alexandre,

I am running the script from tools -> powershell.

I have rewritten the script, this was to simplify things as i had scripts calling scripts:


Script:


###################################################################################################################################
# FILE : RDMImport.ps1
# AUTHOR : Dave Fox
# DATE : 28 Feb 2018
# REVISED : 1 - 28 Feb 2018
# PURPOSE : Import CSV into RDM
###################################################################################################################################

###################################################################################################################################
#
#Section 1 - Set RDM data source to DOD
#
###################################################################################################################################

##################################################
# variables #
##################################################

$database = 'a86b49bc-439c-45e4-872b-aa5ed7522e5d'
$rdmdata
$rdmdetail

$list = get-rdmdatasource

set-rdmcurrentdatasource $database

##################################################
# open csv file #
##################################################

$rdmdata = Import-Csv "c:\dataimport\crm-entry-list.csv" -Delimiter ","

##################################################
# Read Data #
##################################################

ForEach ($rdmdetail in $rdmdata)
{
$ConnectionType =$rdmdetail.("ConnectionType")
$Name =$rdmdetail.("Name")
$Group =$rdmdetail.("Group")
$HostIP =$rdmdetail.("Host")
$Port =$rdmdetail.("Port")
$CredentialUserName =$rdmdetail.("CredentialUserName")
$CredentialPassword =$rdmdetail.("CredentialPassword")
$CredentialDomain =$rdmdetail.("CredentialDomain")
$SSHKeyFile =$rdmdetail.("SSHKeyFile")
$SecurityGroup =$rdmdetail.("SecurityGroup")
$Icon =$rdmdetail.("Icon")
$Arguments =$rdmdetail.("Arguments")
$RDMDelete =$rdmdetail.("RDMDelete")
$RDMUpdate =$rdmdetail.("RDMUpdate")
$Group2 =$rdmdetail.("Group2")
$Group3 =$rdmdetail.("Group3")
$Group4 =$rdmdetail.("Group4")
$Site =$rdmdetail.("Site")


###################################################
# Concatinate Path #
###################################################


If ($Site)
{
$Group = $Group + "\" + $Site
}
If ($Group2)
{
$Group = $Group + "\" + $Group2
}

If ($Group3)
{
$Group = $Group + "\" + $Group3
}

If ($Group4)
{
$Group = $Group + "\" + $Group4
}

###################################################
# select entry type #
###################################################

IF ($RDMUpdate -eq "Y") {

###################################################
# Test for Existing Entry #
###################################################

$Session = Get-RDMSession | Where-Object {$_.Name -eq $Name -and $_.Group -eq $Group}

###################################################
# DM Entry #
###################################################

If ($ConnectionType -eq "DM") {


$Template = "e948d4a8-369f-4161-a2b2-84a0fd3682ba"
write-Host "in DM" -ForegroundColor green
write-Host "$ConnectionType $Name $Group $HostIP $Port $CredentialUserName $CredentialPassword" -ForegroundColor Green
write-Host $Session.ID
If ($Session){
write-Host "Existing Record" -ForegroundColor Magenta
}
Else {
write-host "New Record" -ForegroundColor Yellow
$Session = new-rdmsession -group $Group -host $HostIP -name $Name -setsession -TemplateID $Template -type "CommandLine"
}

update-rdmui
#set-RDMsession $Session.ID

write-host "Updating Record" -ForegroundColor white
Set-RDMSessionProperty $Session.ID -Path "Cmd" -Property "Host" -Value $HostIP

}
#If ($ConnectionType -eq "SSH") {

#}
#}
#If ($ConnectionType -eq "WatchguardVPN") {
#}
#If ($ConnectionType -eq "FSM") {
#}
#If ($ConnectionType -eq "SSL")
#{
#}
#If ($ConnectionType -eq "HTTP") {
#}
#If ($ConnectionType -eq "Avaya") {
#}
#If ($ConnectionType -eq "Telnet") {
#}
#If ($ConnectionType -eq "WinBox") {
#$Template = "0f8a18ef-3031-4a89-a113-91d1d1841f13"

#}
#}

#IF ($RDMUpdate -eq "D") {
#}

}
}

I run the script, first time all ok, Second time it will always treat the first record as new. Please see the attached image

Capture.PNG
Clock2 yrs

Hello,

It is indeed an odd result... Would it be possible that there is an unrecognized or unseen character at the very beginning of your CSV File?
This would explain why it's never to be found in your Get-RDMSession -Name and it might have been trimmed at the New-RDMSession, hence the difference.

I suggest you take a closer look at this. If however you can't see anything, please send us if possible your script file and a sample of your csv file. Make sure that no sensible and personal information are in those files.

Hope this helps.

Regards,



Alex Belisle

signaturesignature

Clock2 yrs