Private/_NewSession.ps1

function _NewSession {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        $Identity
    )
    if (Get-PSSession -Name ADLookups -ErrorAction SilentlyContinue) {
        Remove-PSSession -Name ADLookups
    }

    try {
        if (Test-Connection -ComputerName $Identity -Quiet -Count 1) {
            try {
                $Script:Session = New-PSSession @SessionSplat -Name ADLookups -ComputerName $Identity -ErrorAction Stop -ErrorVariable ErrorVar

                if ($Session) {
                    $ADLookups_ComputerTabOnlineEllipse.Fill = '#FF64DD17' # Green
                    $ADLookups_ComputerTabOnlineTextBlock.Text = 'Online'
                }
                else {
                    $ADLookups_ComputerTabOnlineEllipse.Fill = '#FFDBDD17' # Yellow
                    $ADLookups_ComputerTabOnlineTextBlock.Text = 'Unreachable'
                }
            }
            catch {
                $ADLookups_ComputerTabOnlineEllipse.Fill = '#FFFF6666' # Red
                $ADLookups_ComputerTabOnlineTextBlock.Text = 'Unable to Session'
            }
        }
        else {
            $ADLookups_ComputerTabOnlineEllipse.Fill = '#FFE0E0E0' # Gray
            $ADLookups_ComputerTabOnlineTextBlock.Text = 'Offline'
        }
    }
    catch {
        $ADLookups_ComputerTabOnlineEllipse.Fill = '#FFFF6666' # Red
    }
}