Functions/Add-ManagerEmailAddressProperty.ps1

<#
.SYNOPSIS
    This function adds a ManagerEmailAddress property to a user in Exchange Online
.SYNOPSIS
    This function adds a ManagerEmailAddress property to a user in Exchange Online.
    The property is only added if the user's Manager property is already defined.
    This function assumes that the connection to Exchange Online has already been made.
#>

function Add-ManagerEmailAddressProperty {
    [CmdletBinding(PositionalBinding=$true)]
    param (
        # The user in Exchange Online
        [Parameter(Mandatory=$true)]
        [ValidateNotNull()]
        $user
    )

    # Add the property if the Manager property is defined
    if (![String]::IsNullOrWhiteSpace($user.Manager)) {
        $manager = Get-User -Identity $user.Manager

        # Manager exists, add the manager email address
        if ($manager) {
            $user | Add-Member -NotePropertyName "ManagerEmailAddress" -NotePropertyValue $manager.UserPrincipalName -Force
        }
    }

    # Return the user
    return $user
}