Functions/Get-GSuiteUser.ps1

<#
.SYNOPSIS
    This function retrieves one GSuite user or all GSuite users in a domain.
#>

function Get-GSuiteUser {
    [CmdletBinding(PositionalBinding=$false)]
    [OutputType([Object])]
    param (
        # The access token.
        # It has to be generated using a refresh token, from Get-GSuiteAccessToken
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [String]$token,

        # The primary email address for the user.
        [Parameter(Mandatory=$true, ParameterSetName="Email")]
        [ValidateNotNullOrEmpty()]
        [String]$primaryEmailAddress,

        # The domain for the users.
        [Parameter(Mandatory=$true, ParameterSetName="Domain")]
        [ValidateNotNullOrEmpty()]
        [String]$domain,

        # Whether to retrieve all the GSuite users.
        [Parameter(Mandatory=$true, ParameterSetName="All")]
        [ValidateNotNullOrEmpty()]
        [Switch]$all
    )

    # Retrieve the user with the specified email address
    if ($primaryEmailAddress) {
        $Uri = "https://www.googleapis.com/admin/directory/v1/users/$($primaryEmailAddress)"
    }

    # Retrieve all the users in the specified domain
    elseif ($domain) {
        $Uri = "https://www.googleapis.com/admin/directory/v1/users?domain=$($domain)"
    }

    # Retrieve all the users
    else {
        $Uri = "https://www.googleapis.com/admin/directory/v1/users?customer=my_customer"
    }

    # Prepare the REST call parameters
    $invokeRestMethodParams = @{
        Uri     = $Uri
        Method  = "GET"
        Headers = @{
            Accept        = "application/json"
            Authorization = "Bearer $($token)"
        }
    }

    # Invoke the REST call
    return Invoke-RestMethod @invokeRestMethodParams
}