Scripts/Disconnect-BPAServer.ps1

function Disconnect-BPAServer {
    <#
        .SYNOPSIS
            Disconnect from an AutoMate BPA management server
 
        .DESCRIPTION
            Disconnect-BPAServer removes stored connection information for the management server(s).
 
        .PARAMETER BPAServer
            The AutoMate BPA management server. If the server isn't specified, all servers are removed.
 
        .EXAMPLE
            Disonnect-BPAServer -BPAServer "bpa01" -Credential (Get-Credential)
 
        .NOTES
            Author(s): : David Seibel
            Contributor(s) :
            Date Created : 08/24/2016
            Date Modified : 09/15/2016
 
        .LINK
            https://github.com/davidseibel/PoshBPA
    #>

    [CmdletBinding()]
    param(
        [Parameter(Position = 0)]
        [ValidateNotNullOrEmpty()]
        [string]$BPAServer
    )

    if ($BPAServer) {
        # Disconnect from single server
        if ($global:BPAConnectionInfo.Server -contains $BPAServer) {
            $global:BPAConnectionInfo = $global:BPAConnectionInfo | Where-Object {$_.Server -ne $BPAServer}
            # If no connections remain, discard connection variable
            if (($global:BPAConnectionInfo | Measure-Object).Count -eq 0) {
                Remove-Variable BPAConnectionInfo -Scope Global
            }
        } else {
            throw "Could not find connection to server $BPAServer!"
        }
    } else {
        # Disconnect from all servers
        Remove-Variable BPAConnectionInfo -Scope Global
    }
}