Private/Get-SyncHrManager.ps1

function Get-SyncHrManager
{
    [CmdletBinding(PositionalBinding=$false)]
    param
    (
        [Parameter(Mandatory=$true)][hashtable]$AuthHeader,
        [Parameter(Mandatory=$true)][object[]]$PersonData,
        [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
    }

    $activeEmps = $PersonData | ? {$_.emplStatus -eq 'A' -and $_.empNo.Length -gt 3}

    $progressObj = @{
        count = $activeEmps.Count
        countDown = $activeEmps.Count
        countUp = 0
    }

    try
    {
        foreach ($emp in $activeEmps) 
        {

            Write-Progress -Activity "Getting user's Manager: $($emp.fname) $($emp.lname)" -Status "$(($progressObj).countDown) Users Remaining.."  `
                           -PercentComplete (($($progressObj.countUp) / $($progressObj.count)) * 100) -ErrorAction Ignore

            $progressObj.countDown--
            $progressObj.countUp++


            #$decodedFilter = "{""empNo"":[""eq"", ""OFS-1234""]}"
            #$encodedFilter = Get-EncodedUrl -InputString $decodedFilter --> %7b%22empNo%22%3a%5b%22eq%22%2c%22OFS-1234%22%5d%7d

            $empNoFilter = "%7b%22empNo%22%3a%5b%22eq%22%2c%22$($emp.empNo)%22%5d%7d"
            $url = "$BaseUrl/api/1.0/manager/list?filter=$empNoFilter"
            
            try 
            {
                #$response = Invoke-RestMethod -Method: Get -Uri $url -Headers $($USING:AuthHeader) -ContentType 'application/json'
                $measure = Measure-Command {$response = Invoke-RestMethod -Method: Get -Uri $url -Headers $AuthHeader -ContentType 'application/json'}
                Write-Host -ForegroundColor Yellow "$($emp.empNo) >> $($measure.ToString())"

                $emp | Add-Member -MemberType NoteProperty -Name manager_respTime -Value $measure.ToString() -Force

                $emp.manager_empNo = $response.manager.EmpNo
                $emp.manager_netId = $response.manager.netId
                $emp.manager_name = $response.manager.name
                $emp.manager_role = $response.manager.role

            }
            catch 
            {
                $statusCode = $_.Exception.Response.StatusCode.value__

                Write-Log "Error getting manager for $($emp.empNo)" -LogType: error -ErrorObject $_

                if ($statusCode -eq 401)
                {
                    return
                }

                continue
            }
            
     


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

    Write-Progress -Activity "Complete"  -Completed: $true
    return $PersonData

}