Powershell event not working as expected

Powershell event not working as expected

avatar

I have this session:
forum image

I have a before open event script with this powershell code:

$Path=$RDM.Connection.CommandLine
If (-not(Test-Path -Path "$Path" -PathType Leaf)) {
   $sh = New-Object -ComObject "Wscript.Shell"
   $intButton = $sh.Popup("$($Path) does not exist. Aborting session.",10,"Error: Application not installed",0+16)
   $RDM.Cancel = $True
}


When I start the session the popup comes up and the $RDM session is canceled. So I added some logging lines to the script:

$Path=$RDM.Connection.CommandLine

$Workdir=$RDM.Connection.CommandLineWorkingDirectory
Write-Host "Commandline = $($Path)" *>c:\temp\rdm.txt
Write-Host "------------------------------------------------------------------------------" *>>c:\temp\rdm.txt
Write-Host "WorkingDirectory = $($Workdir)" *>>c:\temp\rdm.txt
Write-Host "------------------------------------------------------------------------------" *>>c:\temp\rdm.txt
dir $Workdir *>>c:\temp\rdm.txt
Write-Host "------------------------------------------------------------------------------" *>>c:\temp\rdm.txt
dir "C:\Program Files\Immidio\Flex Profiles" *>>c:\temp\rdm.txt
Write-Host "------------------------------------------------------------------------------" *>>c:\temp\rdm.txt


If (-not(Test-Path -Path "$Path" -PathType Leaf)) {
   $sh = New-Object -ComObject "Wscript.Shell"
   $intButton = $sh.Popup("$($Path) does not exist. Aborting session.",10,"Error: Application not installed",0+16)
   $RDM.Cancel = $True
}


After I started the session I opened the RDM.TXT file to see what was logged and this is its content:

Commandline = "C:\Program Files\Immidio\Flex Profiles\Flex+ Management Console.exe"
------------------------------------------------------------------------------
WorkingDirectory = "C:\Program Files\Immidio\Flex Profiles"
------------------------------------------------------------------------------
dir : Cannot find drive. A drive with the name '"C' does not exist.
At line:9 char:1
+ dir $Workdir *>>c:\temp\rdm.txt
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: ("C:String) [Get-ChildItem], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
 
------------------------------------------------------------------------------


    Directory: C:\Program Files\Immidio\Flex Profiles


Mode                LastWriteTime         Length Name                                                                   
----                -------------         ------ ----                                                                   
d-----        3/24/2021   3:58 PM                de                                                                     
d-----        3/24/2021   3:58 PM                Drivers                                                                
d-----        3/24/2021   3:58 PM                ja                                                                     
d-----        3/24/2021   3:58 PM                nl                                                                     
-a----        9/18/2020   3:04 AM         234176 ActiproSoftware.Shared.Net20.dll                                       
-a----        9/18/2020   3:04 AM        1065472 ActiproSoftware.SyntaxEditor.Net20.dll                                 
-a----        9/18/2020   3:04 AM         168640 ActiproSoftware.WinUICore.Net20.dll                                    
-a----        9/18/2020   3:04 AM         525656 ComponentFactory.Krypton.Navigator.dll                                 
-a----        9/18/2020   3:04 AM        1041752 ComponentFactory.Krypton.Ribbon.dll                                    
-a----        9/18/2020   3:04 AM        2184536 ComponentFactory.Krypton.Toolkit.dll                                   
-a----        9/18/2020   3:08 AM        2232536 Flex+ Management Console.exe                                           
-a----        9/18/2020   3:04 AM            270 Flex+ Management Console.exe.config                                    
-a----        9/18/2020   4:08 AM          38104 Flex+ Resources.dll                                                    
-a----        9/18/2020   4:08 AM         378072 Flex+ Self-Support.exe                                                 
-a----        9/18/2020   4:04 AM            270 Flex+ Self-Support.exe.config                                          
-a----        9/18/2020   3:04 AM          33482 FlexBinarySettings.bin                                                 
-a----        9/18/2020   4:08 AM        1930456 FlexEngine.dll                                                         
-a----        9/18/2020   4:08 AM         871984 FlexEngine.exe                                                         
-a----        9/18/2020   4:08 AM         490200 FlexHook32.dll                                                         
-a----        9/18/2020   4:08 AM         618712 FlexHook64.dll                                                         
-a----        9/18/2020   4:04 AM          10216 FlexHookDriver64.cat                                                   
-a----        9/18/2020   4:04 AM           1302 FlexHookDriver64.inf                                                   
-a----        9/18/2020   4:04 AM         159672 FlexHookDriver64.sys                                                   
-a----        9/18/2020   4:09 AM         286768 FlexMigrate.exe                                                        
-a----        9/18/2020   4:08 AM        1056472 FlexService.exe                                                        
-a----        9/18/2020   4:09 AM         184536 UEMResult.exe                                                          
-a----        9/18/2020   4:04 AM            267 UEMResult.exe.config                                                   


------------------------------------------------------------------------------


When I change the script line:
$Path=$RDM.Connection.CommandLine to $Path="C:\Program Files\Immidio\Flex Profiles\Flex+ Management Console.exe" all is working fine.

Why does the $RDM.Connection.Commandline and $RDM.Connection.CommandLineWorkingDirectory values fail?

All Comments (3)

avatar

Hello Jasper,

When working with a session in PowerShell, the connection is implied.

Simply change them to $RDM.Commandline and $RDM.CommandLineWorkingDirectory, both should return the correct value.

Best regards,

Richard Boisvert

avatar

Hello Richard,

Thank you, that fixed the issue.
I have tried to search for documentation on the $RDM object but couldn't find it. Do you know if there is any documentation and where to read/download it?

Regards,

Jasper Kimmel

avatar

Hello Jasper,

The first step would be to use the help of all the cmdlets. To get a list of the commands: Get-Command -Module RemoteDesktopManager.PowerShellModule

We have a GitHub we a lot of samples that can provide you with some guidance: https://github.com/Devolutions/RDMSamples-ps. You can also refer to the forum dedicated to PowerShell: https://forum.devolutions.net/forums/42/remote-desktop-manager--powershell-repository

One of the most useful tips is the first one provided in https://help.remotedesktopmanager.com/pstipsandtricks.html

Those should help you get started.

Please note, however, that the PS module provided with the 2021.2 release will be changed and it will support PowerShell 7. This will make it supported in Linux and macOS too!

Best regards,

Richard Boisvert