I am finalizing the creation of a module for disabling employees across AD, Exchange and Lync. In the script I am loading the AD module and setting up 2 remote sessions, one for Lync and one for Exchange. Since this module will need to be used by anyone who has the proper rights, I would like to be able to check for the existing Lync and Exchange remote sessions before loading them in the script. I know that some people may have already loaded them in their PowerShell profile.
I have seen several different methods for doing this, such as… if ($RemoteExchange_LocalizedStrings) or get-pssession or even if (-not(Get-PsSession)).
What is the recommended method of finding existing sessions in PowerShell 4?