Public/Authentication/Get-SIASession.ps1

function Get-SIASession {
    <#
    .SYNOPSIS
        Returns the active psSIA session, if one exists.
    .DESCRIPTION
        Reads the in-memory session created by New-SIASession. Returns nothing
        if no session is active. The access token is exposed as a SecureString;
        psSIA never writes the plaintext token to the pipeline, the console, or
        any log.
    .EXAMPLE
        Get-SIASession

        Shows the current session's tenant, client ID, and token expiry.
    .INPUTS
        None.
    .OUTPUTS
        psSIA.Session
    .LINK
        https://api-docs.cyberark.com/create-api-token/docs/create-api-token
    #>

    [CmdletBinding()]
    [OutputType('psSIA.Session')]
    param()

    if (-not $script:SIASession) {
        return
    }

    $session = $script:SIASession.PSObject.Copy()
    $session | Add-Member -NotePropertyName IsExpired -NotePropertyValue `
        ((Get-Date).ToUniversalTime() -ge $script:SIASession.ExpiresAt) -Force -PassThru
}