Delete RDM session via bulk edit powershell

Delete RDM session via bulk edit powershell

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

Hi btimmer1,

I am not sure what the variable $rdm represents in your example, so I will ignore it.

To save the new url, you can use Set-RDMSession cmdlet.

For the Remove-RDMSession, you must pass the PSConnection object or its ID. Also, the -Force flag can be used to avoid confirmation prompt. However, be careful to make sure only the desired connections will be treated. If you send an entry without an URL value, it will be deleted. I recommended you fully test before adding the flag.

It seems that Resolve-DNSName returns a non-terminating error. You can try by adding -ErrorAction Stop to the resolve-dnsname call.

try
{
  $connection.URL = (resolve-dnsname $connection.URL -netbiosfallback -nohostsfile -type A -ErrorAction Stop).ipaddress
 
  Set-RDMSession $connection
}
catch
{
  Remove-RDMSession $connection
}


Hope that helps,

Maxime Bernier