Functions/Get-EmailAddressDomain.ps1

<#
.SYNOPSIS
    This function extracts the domain portion of an email address.
.DESCRIPTION
    This function extracts the domain portion of an email address.
    The domain is the portion of the email after the '@' character.
    If the email is invalid, an empty string is returned.
.EXAMPLE
    Get-EmailAddressDomain -EmailAddress "mailbox@domain.com"
#>

function Get-EmailAddressDomain {
    [CmdletBinding()]
    [OutputType([String])]
    param (
        # The email address which the domain will be extracted from.
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [String]$emailAddress
    )

    # Check email validity
    if (!(Test-EmailAddressValidity -EmailAddress $emailAddress)) {
        return $null
    }

    # Extract domain
    return $emailAddress -replace "^[\S]+@([\S]*?)$", "`$1"
}