Public/Get-ADPLastName.ps1

function Get-ADPLastName {
    <#
    .SYNOPSIS
        Get a user's Last Name from ADP

    .DESCRIPTION
        Get a user's Last Name from ADP

    .PARAMETER ADPObject
        Object which holds the Last Name

    .EXAMPLE
        Input Object: ADP Object
        Return String: <Last Name>

    .NOTES
        This is used when passing the full adp worker object from ADP's APID

    .FUNCTIONALITY
        Powershell Language
    #>

    [CmdletBinding()]
    param (
        [Parameter( Mandatory = $true,
            Position = 0,
            ValueFromPipeline = $true
        )]
        $ADPObject
    )

    $localLastName = $null
    try {
        $localLastName = $ADPObject.person.preferredName.familyName1
    }
    catch {}
    try {
        if (!$localLastName) {
            $localLastName = $ADPObject.person.legalName.familyName1
        }
    }
    catch {}

    return ( $localLastName | Get-ValidADPReturn )
}