Public/Get-SyncHrLocation.ps1

function Get-SyncHrLocation
{
    [CmdletBinding(PositionalBinding=$false)]
    param
    (
        [Parameter(Mandatory=$true)][object[]]$PersonDataInput,
        [Parameter(Mandatory=$true)][hashtable]$AuthHeader,
        [Parameter(Mandatory=$false)][string]$BaseUrl = 'https://clients.synchr.com/synchr'
    )

    if ($AuthHeader.Authorization -notmatch 'SHR apiKey') {
        Write-Log -LogText "Invalid AuthHeader. Use Get-SyncHrAuthHeader first."
        throw "Invalid AuthHeader. Use Get-SyncHrAuthHeader first."
        return
    }

    try
    {

        $url = "$BaseUrl/api/1.0/location/list"

        Write-Log -LogText "Getting SyncHr Locations >> $url"

        $response = Invoke-RestMethod -Method Get -Uri $url -Headers $AuthHeader -ContentType 'application/json' -Verbose:$false
        $locations = $response.location

        Write-Log -LogText "Locations returned: $($locations.Count)"

        if ($locations.Count -lt 1)
        {
            return $PersonDataInput
        }

        foreach ($emp in $PersonDataInput)
        {
            if ($emp.emplStatusDescription -eq 'Active Employee')
            {
                $location = $locations | ? {$_.locationCode -eq $emp.locationCode}

                if ($location)
                {
                    $emp.location_name = $location.locationDescription
                    $emp.location_street = $location.streetAddress
                    $emp.location_city = $location.city
                    $emp.location_state = $location.stateProvinceCode
                    $emp.location_zip = $location.postalCode
                    $emp.location_country = $location.countryCode
                }
                else 
                {
                    Write-Log -LogText "No valid location found in SyncHr for >> $($emp.fName) $($emp.lName) $($emp.empNo) >> LocationCode: ""$($emp.loctionCode)""" -LogType warning
                }
            }
        }

        return $PersonDataInput

    }
    catch
    {
        Write-Log "Unhandled exception" -LogType: error -ErrorObject $_
        throw $_
    }

}