Hi!
I have a script creating new sessions.
$session = New-RDMSession -Type Group -Group $sessionFolder -Name $entryName -SetSession Set-RDMSession -Session $session -Refresh
Works fine. But if I ran the script while the RDM UI is running. the powershell crashes. The script stops on the Set-RDMSession command and I have to kill the powershell session.
How can I check if the RDM UI is running? Or can I do something to run the script with running RDM UI?
CU,
Timo
Hi!
I found this solution/workaround:
function killRDMUI{
$p = Get-Process RemoteDesktopManager -ErrorAction SilentlyContinue
if ($p) {
write-Host Closing RDM...
# try gracefully first
$tmp = $p.CloseMainWindow()
$i = 0;
while(($i -lt 10) -and (-not $p.HasExited)){
Sleep 1
$i = $i +1
}
if (!$p.HasExited) {
write-Host Had to kill RDM!
$p | Stop-Process -Force
}
}
}Based on this: powershell - How to Correctly Check if a Process is running and Stop it - Stack Overflow
Not an ideal solution, but prevent the script to crash.
CU,
Timo
In your original script, you are saving your entry twice.
You don't need to call Set-RDMSession if you use New-RDMSession with -SetSession.
You could also try removing the -Refresh switch. Depending on the rest of your script, you might not need it and will only slow the script execution (or crash PS for some reasons in your case).
Still, I'll take a look at what could cause that crash when calling Set-RDMSession.
Let me know if this helps.
Regards
Jonathan Lafontaine