Forum / Remote Desktop Manager - PowerShell Repository

how to update currently selected session

  • Create an Issue
  • Cancel

I think this my be an easy question but I am just not seeing it. What I want to do is update the currently selected session.


In detail: I am running a script to produce a filtered list of services running on the remote server and I want to take the output which is assigned to variable and update the description field with it. I cant seem to figure out work with the current session (think it is just getting the session ID of the currently selected session)

Clock4 yrs

Hello,

If you want to update the description of the current session, you have to pass the ID of the session as an argument to your PowerShell script. You can use the RDM variable $SESSION_ID$. Also, you have to enable the Load RDM CmdLet option in the PowerShell entry's properties.

2016+05+09+14+32+21

Finally, you have to use the Set-RDMSessionProperty to update the description.

[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$sessionID)

Update-RDMUI
$newDescription = "New Description"
Set-RDMSessionProperty -ID $sessionID -Property "Description" -Value $newDescription


Please note that you should probably use the Update-RDMUI for refreshing the actual Data Source because sometime the current Data Source isn't correctly updated within the PowerShell script.

Best regards,



Érica Poirier

signaturesignature

2016-05-09_14-32-21.png
Clock4 yrs

is this doable with a Powershell(Remote). doesnt seem to have that option. Here is the actual script (obviously will be making changes to send the output to a variable.

Get-WmiObject Win32_service |Where-Object {$_.Startmode -eq "Auto" -and $_.startname -ne "NT AUTHORITY\LocalService" -and $_.startname -ne "LocalSystem" -and $_.startname -ne "NT Authority\NetworkService"}|Group-Object -Property StartName | Format-Table Name, Count -auto

The intent of this is get a list of some of the services from the remote PC and have it saved to the description

2016-05-09_1504.png
Clock4 yrs

Hello,

I forgot to mention that you cannot use the Remote PowerShell entry to modify the selected session. You have to manage the remote connection inside a Local PowerShell entry in order to retrieve the result of the service list and save it in the description of the selected session.

Here is an example of this script :

[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$sessionID,
[Parameter(Mandatory=$True,Position=2)]
[string]$hostName
)

$script = {Get-WmiObject Win32_service | Where-Object {$_.Startmode -eq "Auto" -and $_.startname -ne "NT AUTHORITY\LocalService" -and $_.startname -ne "LocalSystem" -and $_.startname -ne "NT Authority\NetworkService"} | Group-Object -Property StartName | Format-Table Name, Count -auto | Out-String}

$psSession = New-PSSession -ComputerName $hostName
[string]$newDescription = Invoke-Command -Session $psSession -ScriptBlock $script
Remove-PSSession -Session $psSession

Update-RDMUI

Set-RDMSessionProperty -ID $sessionID -Property "Description" -Value $newDescription


And don't forget to add the $HOST$ variable in the argument field of the Local PowerShell entry!
2016+05+10+10+05+03

Best regards,



Érica Poirier

signaturesignature

2016-05-10_10-05-03.png
Clock4 yrs