Private/Disconnect-CitrixADC.ps1

function Disconnect-CitrixADC {
    <#
    .SYNOPSIS
        Disconnect session with NetScaler.
    .DESCRIPTION
        Disconnect session with NetScaler.
    .EXAMPLE
        Disconnect-NetScaler
        Disconnect from default NetScaler session.
    .EXAMPLE
        Disconnect-NetScaler -Session $session
        Disconnect from specific NetScaler session object $session.
    .PARAMETER Session
        The NetScaler session object
    .CREDITS
        Used this module from the Citrix NetScaler Automation Framework that can be found on the Citrix Blogs
    #>

    [cmdletbinding()]
    param(
        $Session = $script:session
    )

    try {
        Write-Verbose -Message 'Logging out of NetScaler'
        $params = @{
            Uri         = $Session.CreateUri("config", "logout")
            Body        = ConvertTo-Json -InputObject @{logout = @{}}
            Method      = 'POST'
            ContentType = 'application/json'
            WebSession  = $session.WebSession
        }
        try {
            Invoke-RestMethod @params
        }
        catch {
            throw $_
        }
    }
    catch {
        throw $_
    }
}