Adding PSRemote subconnections for all RDPConfigured connections via Powershell

Adding PSRemote subconnections for all RDPConfigured connections via Powershell

avatar

Hello,
Would anyone happen to know of a way to script out adding PSRemote subconnections to all current RDPConfigured connections I have set up in RDM? I recently imported our whole server list from our old sharepoint site, and would love to be able to mass add subconnections to each of them via a script. A bonus if I can add them all with the 'Run As Admin' box checked off as well.

This is one I set up manually, just using the $PARENT_NAME$ variable.

forum image

Thanks in advance for any help!

All Comments (4)

avatar

Hello,

This is achievable by calling Invoke-RDMParentSession.
This command requires -ParentSession and -Session, and optionally the switches -Refresh, -UseInheritedVPN and -UseParentCredentials

Obviously sou will need to create the sub session beforehand (New-RDMSession)

I hope this helps!

Best regards,

Alex Belisle

avatar

Hello,

this may give you an idea how you could start:

Get-RDMSession | where {$_.ConnectionType -eq 'RDPConfigured'} | ForEach-Object {New-RDMSession -ConnectionType 'PowerShellRemoteConsole' -Name '$PARENT_NAME$' -Host '$PARENT_HOST$' -SetSession | Invoke-RDMParentSession -ParentSession $_}

Please create always a backup before you run such scripts!

Regards,
Min

avatar

Thanks Min! That's pretty much what I was able to come up with after going off what Alexandre provided. This works for the most part, however it seems to be inserting two records. One sub-connection as expected, but also its own parent record:
forum image
Any thoughts?

EDIT: I ended up going with this solution and just deleting the extra Parent sessions it created. Was an easy enough job.

My real question now, is is possible to select all of these entries and enable 'Run As Admin'?
forum image
I know with an RDP session, you check off boxes like 'Is Virtual Machine by calling something like the following, but haven't found if there's a similar call for Run As Admin with PowershellRemoteConsole
$ServerEntry = New-RDMSession -Name $DeviceName -Host $DeviceName -Type "$Type"
$ServerEntry.MetaInformation.IsVirtualMachine "True"
Set-RDMSession $ServerEntry 
Update-RDMUI
}

avatar

Hello,

the "Run as Administrator" can be enabled with the following Custom Powershell command [Edit => Edit (Special Actions)]:

$Connection.Powershell.RunAsAdministrator= $true;
$RDM.Save();

Regards,
Min