Functions/Remove-GSuiteUserAlias.ps1

<#
.SYNOPSIS
    This function removes an alias of a GSuite user.
#>

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

        # The alias of the user to remove.
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [String]$alias
    )

    # Validate that the 'connection' has been established and the user access token exists
    Assert-GSuiteConnection -Scope "User"

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

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

    # If the removal is successful, $response will be an empty string
    if ("" -eq $response) {
        return $true
    }
    else {
        return $false
    }
}