Functions/Get-GSuiteUserAlias.ps1

<#
.SYNOPSIS
    This function gets alias information of a GSuite user.
    This function returns either String when there is one alias, or Object[] when there is more than one alias.
    This returns the same result as (Get-GSuiteUser -primaryEmailAddress $primaryEmailAddress).alias
#>

function Get-GSuiteUserAlias {
    [CmdletBinding(PositionalBinding=$false)]
    [OutputType([Object[]], [String])]
    param (
        # The primary email address of the user.
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [String]$primaryEmailAddress
    )

    # Validate that the 'connection' has been established
    if (!$Global:GSuiteAccessTokensHashTable) {
        throw "You must call the Connect-GSuiteAdminAccount cmdlet before calling any other GSuite cmdlets."
    }

    # Validate that the user access token exists in the hash table
    if ([String]::IsNullOrWhiteSpace($Global:GSuiteAccessTokensHashTable.User)) {
        throw "User access token is required to call Get-GSuiteUserAlias."
    }

    # Prepare REST call parameters
    $invokeRestMethodParams = @{
        Uri     = "https://www.googleapis.com/admin/directory/v1/users/$($primaryEmailAddress)/aliases"
        Method  = "GET"
        Headers = @{
            Accept        = "application/json"
            Authorization = "Bearer $($Global:GSuiteAccessTokensHashTable.User)"
        }
    }

    # Invoke the REST call
    $response = Invoke-RestMethod @invokeRestMethodParams

    # return the aliases of the user
    return $response.aliases.alias
}