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"
        "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"
    }
    

    # $codes = [PSCustomObject]@{
    # 201 = [PSCustomObject]@{
    # division = "Revenue"
    # department = "Customer Success"
    # }
    # 204 = [PSCustomObject]@{
    # division = "Revenue"
    # department = "Customer Success"
    # }
    # 205 = [PSCustomObject]@{
    # division = "Revenue"
    # department = "Customer Support"
    # }
    # 206 = [PSCustomObject]@{
    # division = "Revenue"
    # department = "Customer Success"
    # }
    # 209 = [PSCustomObject]@{
    # division = "Revenue"
    # department = "Customer Success"
    # }
    # 502 = [PSCustomObject]@{
    # division = "Engineering"
    # department = "QA"
    # }
    # 503 = [PSCustomObject]@{
    # division = "Engineering"
    # department = "Project Management"
    # }
    # 506 = [PSCustomObject]@{
    # division = "Engineering"
    # department = "Data & Strategy"
    # }
    # 507 = [PSCustomObject]@{
    # division = "Engineering"
    # department = "Development"
    # }
    # 508 = [PSCustomObject]@{
    # division = "Engineering"
    # department = "InfoSec"
    # }
    # 509 = [PSCustomObject]@{
    # division = "Engineering"
    # department = "Development"
    # }
    # 510 = [PSCustomObject]@{
    # division = "Executive"
    # department = "Engineering & Product"
    # }
    # 601 = [PSCustomObject]@{
    # division = "Product"
    # department = "Product Management & Design"
    # }
    # 602 = [PSCustomObject]@{
    # division = "Product"
    # department = "Product Management & Design"
    # }
    # 603 = [PSCustomObject]@{
    # division = "Product"
    # department = "Product Management & Design"
    # }
    # 701 = [PSCustomObject]@{
    # division = "Revenue"
    # department = "Sales"
    # }
    # 702 = [PSCustomObject]@{
    # division = "Revenue"
    # department = "Sales"
    # }
    # 705 = [PSCustomObject]@{
    # division = "Partnerships"
    # department = "Operations"
    # }
    # 706 = [PSCustomObject]@{
    # division = "Revenue"
    # department = "Services"
    # }
    # 707 = [PSCustomObject]@{
    # division = "Revenue"
    # department = "Pre-Sales"
    # }
    # 710 = [PSCustomObject]@{
    # division = "Revenue"
    # department = "Business Development"
    # }
    # 711 = [PSCustomObject]@{
    # division = "Revenue"
    # department = "Operations"
    # }
    # 801 = [PSCustomObject]@{
    # division = "Marketing"
    # department = "Demand Generation"
    # }
    # 804 = [PSCustomObject]@{
    # division = "Marketing"
    # department = "Product Marketing"
    # }
    # 806 = [PSCustomObject]@{
    # division = "Marketing"
    # department = "Solutions"
    # }
    # 807 = [PSCustomObject]@{
    # division = "Marketing"
    # department = "Creative & Design"
    # }
    # 808 = [PSCustomObject]@{
    # division = "Marketing"
    # department = "Syndication"
    # }
    # 901 = [PSCustomObject]@{
    # division = "Finance"
    # department = "Finance"
    # }
    # 902 = [PSCustomObject]@{
    # division = "Executive"
    # department = "Office of the CEO"
    # }
    # 905 = [PSCustomObject]@{
    # division = "People"
    # department = "Operations"
    # }
    # 906 = [PSCustomObject]@{
    # division = "People"
    # department = "Talent Acquisition"
    # }
    # 907 = [PSCustomObject]@{
    # division = "Operations"
    # department = "IT"
    # }
    # 908 = [PSCustomObject]@{
    # division = "Operations"
    # department = "Legal"
    # }
    # 910 = [PSCustomObject]@{
    # division = "Engineering"
    # department = "Project Management"
    # }
    # 911 = [PSCustomObject]@{
    # division = "Engineering"
    # department = "InfoSec"
    # }
    # }

    # $localOrgStructure = [PSCustomObject]@{
    # division = $null;
    # department = $null;
    # combined = $null;
    # }
    # $localTitle = ($ADPObject | Get-ADPTitle ).ToLower()

    $localOrgStructure = $null
    $leadershipCode = $null

    try {
        $localOrgStructure = ($ADPObject.workAssignments | Where-Object { $_.primaryIndicator }).homeOrganizationalUnits[1].nameCode.shortname
        $localOrgStructure = ( $localOrgStructure | Get-ValidADPReturn )
        $localOrgStructure = $codes.$localOrgStructure
    }
    catch {}

    try {
        $leadershipCode = ($ADPObject.customFieldGroup.codeFields | Where-Object { $_.nameCode.codeValue -eq "Leadership Team" }).codeValue
        $leadershipCode = ($leadershipCode | Get-ValidADPReturn)
    }
    catch {}

    if ($leadershipCode -eq "SLT") {
        $localOrgStructure += " XLT"
    }
    # $localOrgStructure.division = $codes.$orgCode.division
    
    #fix slt
    # if ($leadershipCode -eq "SLT" -and $localOrgStructure.division -ne "Executive") {
    # $localOrgStructure.department = $localOrgStructure.division
    # $localOrgStructure.division = "Executive"
    # } elseif ($localOrgStructure.division -eq "Executive" -and $leadershipCode -ne "SLT") {
    # $localOrgStructure.division = "Operations"
    # $localOrgStructure.department = $codes.$orgCode.department
    # } elseif ($leadershipCode -eq "XLT") {
    # $localOrgStructure.department = "Leadership"
    # } else {
    # $localOrgStructure.department = $codes.$orgCode.department
    # }

    #fix one offs
    # switch ($localOrgStructure.division) {
    # "Finance" {
    # switch -wildcard ($localTitle) {
    # "*fp&a*" { $localOrgStructure.department = "FP&A"; break }
    # "*account*" { $localOrgStructure.department = "Accounting"; break }
    # Default {}
    # }
    # }
    # "Engineering" {
    # switch -wildcard ($localTitle) {
    # "*site reliability*" { $localOrgStructure.department = "Platform"; break }
    # "*cloud*" { $localOrgStructure.department = "Platform"; break }
    # "*platform*" { $localOrgStructure.department = "Platform"; break }
    # Default {}
    # }
    # }
    # Default {}
    # }

    # $localOrgStructure.combined = "$($localOrgStructure.division) | $($localOrgStructure.department)"

    # $localOrgStructure.division = ( $localOrgStructure.division | Get-ValidADPReturn )
    # $localOrgStructure.department = ( $localOrgStructure.department | Get-ValidADPReturn )
    # $localOrgStructure.combined = ( $localOrgStructure.combined | Get-ValidADPReturn )

    return ( $localOrgStructure | Get-ValidADPReturn )
}