Public/Get-SyncHrPersonData.ps1
function Get-SyncHrPersonData { [CmdletBinding(PositionalBinding=$false)] param ( [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 { $counter = 0 $offsetCounter = 0 $url = "$BaseUrl/api/1.0/PersonData/list" $returnList= @() while($counter -lt 50) { $counter++ $offsetUrl = "$($url)?offset=$offsetCounter" Write-Log -LogText "Fetching PersonData $counter >> $offsetUrl" $response = Invoke-RestMethod -Method Get -Uri $offsetUrl -Headers $AuthHeader -ContentType 'application/json' -Verbose:$false if ($response.PersonData -ne $null) { foreach ($record in $response.PersonData) { $record.empNo = $record.empNo -replace ' - ', '-' -replace '_', '-' $record | Add-Member -MemberType: NoteProperty -Name prefix -Value $($record.empNo -replace '-\d+') -Force $record | Add-Member -MemberType NoteProperty -Name manager_empNo -Value $null -Force $record | Add-Member -MemberType NoteProperty -Name manager_netId -Value $null -Force $record | Add-Member -MemberType NoteProperty -Name manager_name -Value $null -Force $record | Add-Member -MemberType NoteProperty -Name manager_role -Value $null -Force $record | Add-Member -MemberType NoteProperty -Name manager_errorMsg -Value $null -Force $record | Add-Member -MemberType NoteProperty -Name manager_respTime -Value $null -Force $record | Add-Member -MemberType NoteProperty -Name location_name -Value $null -Force $record | Add-Member -MemberType NoteProperty -Name location_street -Value $null -Force $record | Add-Member -MemberType NoteProperty -Name location_city -Value $null -Force $record | Add-Member -MemberType NoteProperty -Name location_state -Value $null -Force $record | Add-Member -MemberType NoteProperty -Name location_zip -Value $null -Force $record | Add-Member -MemberType NoteProperty -Name location_country -Value $null -Force } $returnList += $response.PersonData } if ($response.PersonData.Count -lt 200) { Write-Log -LogText "COMPLETED Fetching PersonData! Total: $($returnList.Count)" return $returnList } $offsetCounter = $offsetCounter + 200 } return $returnList } catch { Write-Log "Unhandled exception" -LogType: error -ErrorObject $_ throw $_ } } |