Private/Connect-MMExchangeServer.ps1

function Connect-MMExchangeServer {

    # Connect-ExchangeServer
    # https://learn.microsoft.com/en-us/powershell/exchange/connect-to-exchange-servers-using-remote-powershell?view=exchange-ps

    $local_session = Get-PSSession
    If (!$local_session) {
        # $UserCredential = Get-Credential
        $local_session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://<ServerFQDN>/PowerShell/ -Authentication Kerberos #-Credential $UserCredential
        Import-PSSession $local_session -DisableNameChecking -Prefix "EXCH" # ES?
    } else {
        # Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
    }
    # Remove-PSSession $Session

    <#
    if (!($env:ExchangeInstallPath)) {
        throw "Exchange Server system variable ExchangeInstallPath missing."
    }
 
    if ($env:ExchangeInstallPath -notmatch '\\V15\\') {
        write-warning "The Microsoft Exchange Management Shell will be loaded from '$($env:ExchangeInstallPath)'"
        write-warning "Exchange Server 2016 powershell module not detected. There may be issues."
    }
 
    try {
        $cmd = $null; $cmd = get-command 'get-mailbox' -erroraction stop
    } catch {
        $invexpr = ". '$env:ExchangeInstallPath\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto -ClientApplication:ManagementShell"
        Invoke-Expression $invexpr
    }
 
    try {
        $cmd = $null; $cmd = get-command 'get-mailbox' -erroraction stop
    } catch {
        throw "Unable to load the Microsoft Exchange Management Shell."
    }
    #>


    return $local_session
}