Bulk delete RDM sessions via powershell edit

Bulk delete RDM sessions via powershell edit

avatar

I am trying to go through our list of servers, and delete the entries from the data source that are no longer valid\around (based on the fact that a DNS lookup fails for them) while simultaneously changing the connection URL to IP from DNS. I'm not sure the command to do this.. I started to come up with this, but I can't figure a way to get it to delete the RDM session on error (or on failed DNS lookup rather).. This is what I have so far. Any help on where to go from here?? The stuff in the 'catch' section are just things I've tried that I know don't work.. I'm not a PowerShell expert, yet... lol

try
{
$connection.URL = (resolve-dnsname $connection.URL -netbiosfallback -nohostsfile -type A).ipaddress
$rdm.save();
}
catch
{
Remove-RDMSession $rdm.name
$rdm.delete();
}

All Comments (1)

avatar

Hello,

Sorry for the long delay, I had to test around for this one.
I believe you're trying this in a Edit (Special Action) > Custom PowerShell Command.
I could not get a session deleted this way (but you could make it expired if it's better)

That said, the kind of operations you're attempting would be possible through a PowerShell entry, or even in a Macro/Script/Tools > PowerShell (Local).
The script would look like this :

# I made it for a PowerShell entry, for RDP connections in a given folder (ThisFolder in my context)
$rdp = Get-RDMSession -GroupName "ThisFolder" | Where-Object {$_.ConnectionType -eq "RDPConfigured"}
foreach ($c in $rdp){
  $res = Resolve-DnsName $c.Host -NetbiosFallback -NoHostsFile -Type A
  If ($null -eq $res){
    Remove-RDMSession $c
  }
}

I hope this helps.
Best regards,

Alex Belisle