Public/Get-ADPOrgStructure.ps1
function Get-ADPOrgStructure { <# .SYNOPSIS Get a user's Division and Department from ADP .DESCRIPTION Get a user's Division and Department from ADP .PARAMETER ADPObject Object which holds the Division and Department .EXAMPLE Input Object: ADP Object Return Object: {division, department, combined} .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 ) $codes = [PSCustomObject]@{ "FIN - Accounting" = "Finance | Accounting" "FIN - Finance" = "Executive | Finance" "FIN - FP&A" = "Finance | FP&A" "FIN - Legal" = "Operations | Legal" "FIN - Payroll" = "Finance | Payroll" "MKTG - Brand & Content" = "Marketing | Brand & Content" "MKTG - Business Development" = "Marketing | Business Development" "MKTG - Operations" = "Marketing | Operations" "MKTG - Results Foundry" = "Marketing | Results Foundry" "MKTG - Marketing" = "Executive | Marketing" "P&E - Data & Strategy" = "Engineering | Data & Strategy" "P&E - Engineering" = "Executive | Engineering & Product" "P&E - Info Security" = "Engineering | InfoSec" "P&E - Integrations" = "Engineering | Core Services" "P&E - IT" = "Operations | IT" "P&E - Platform" = "Engineering | Platform" "P&E - Product Management" = "Product | Product Management & Design" "P&E - QA" = "Engineering | QA" "P&E - Software Development" = "Engineering | Development" "PPL - Operations" = "People | Operations" "PPL - Talent Acquisition" = "People | Recruiting" "PTN - Partnerships" = "Executive | Partnerships" "PTN - Operations" = "Partnerships | Operations" "REV - Customer Success" = "Revenue | Customer Success" "REV - Customer Support" = "Revenue | Customer Support" "REV - Revenue" = "Executive | Revenue" "REV - Sales" = "Revenue | Sales" "REV - Solution Consultant" = "Revenue | Pre-Sales" "REV - Strategic Services" = "Revenue | Services" "WorkBoard - Office of the CEO" = "Executive | Office of the CEO" } $localOrgStructure = [PSCustomObject]@{ department = $null costCenter = $null } # $localOrgStructure = $null $localOrgCode = $null $leadershipCode = $null $costCenterCode = $null #department try { $localOrgCode = ($ADPObject.workAssignments | Where-Object { $_.primaryIndicator }).assignedOrganizationalUnits[0].nameCode.shortname if ($null -eq $localOrgCode) { $localOrgCode = ($ADPObject.workAssignments | Where-Object { $_.primaryIndicator }).assignedOrganizationalUnits[0].nameCode.longName } $localOrgStructure.department = $codes.$localOrgCode } catch {} #xlt try { $leadershipCode = ($ADPObject.customFieldGroup.codeFields | Where-Object { $_.nameCode.codeValue -eq "Leadership Team" }).codeValue $leadershipCode = ($leadershipCode | Get-ValidADPReturn) } catch {} if ($leadershipCode -eq "XLT") { $localOrgStructure.department += " XLT" } #cost center try { $localOrgStructure.costCenter = ($ADPObject.workAssignments | Where-Object { $_.primaryIndicator }).assignedOrganizationalUnits[1].nameCode.codeValue $localOrgStructure.costCenter += " - " $costCenterCode = ($ADPObject.workAssignments | Where-Object { $_.primaryIndicator }).assignedOrganizationalUnits[1].nameCode.shortName if ($null -eq $costCenterCode) { $costCenterCode = ($ADPObject.workAssignments | Where-Object { $_.primaryIndicator }).assignedOrganizationalUnits[1].nameCode.longName } $localOrgStructure.costCenter += $costCenterCode } catch {} $localOrgStructure.department = ( $localOrgStructure.department | Get-ValidADPReturn ) $localOrgStructure.costCenter = ( $localOrgStructure.costCenter | Get-ValidADPReturn ) return $localOrgStructure | Get-ValidADPReturn } |