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
    )

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

    $orgCode = $null
    try {
        $orgCode = ($ADPObject.workAssignments | Where-Object { $_.primaryIndicator }).assignedOrganizationalUnits[1].nameCode.codeValue
        $orgCode = ( $orgCode | Get-ValidADPReturn )
    }
 catch {}

    #modify org code for exceptions
    switch ($orgCode) {
        #people
        "000905" {
            if ( $localTitle -like "*vice president*" -or $localTitle -like "*vp*" ) {
                $orgCode = "1000905"
            }
            break
        }
        #revenue
        "000701" {
            if ( $localTitle -like "*chief*" -or $localTitle -like "*executive assistant*") {
                $orgCode = "1000701"
            }
            break
        }
        #finance
        "000901" {
            if ( $localTitle -like "*chief*"  ) {
                $orgCode = "1000901"
            }
            elseif ( $localTitle -like "*fp&a*" ) {
                $orgCode = "2000901"
            }
            else {
                $orgCode = "3000901"
            }
            break
        }
        #engineering
        "000509" {
            if ($localTitle -like "*site reliability*" -or $localTitle -like "*cloud*") {
                $orgCode = "1000509"
            }
        }
        default {}
    }

    switch ($orgCode) {
        #executive
        { "1000905", "1000701", "000810", "000610", "000510", "1000901", "000902" -eq $_ } {
            $localOrgStructure.division = "Executive"
            switch ($orgCode) {
                "1000905" { $localOrgStructure.department = "People"; break }
                "1000701" { $localOrgStructure.department = "Revenue"; break }
                "000810" { $localOrgStructure.department = "Marketing"; break }
                "000610" { $localOrgStructure.department = "Product"; break }
                "000510" { $localOrgStructure.department = "Engineering"; break }
                "1000901" { $localOrgStructure.department = "Finance"; break }
                "000902" { $localOrgStructure.department = "Office of the CEO"; break }
            }
            $localOrgStructure.combined = "$($localOrgStructure.division) | $($localOrgStructure.department)"
            break
        }
        #people
        { "000905", "000906" -eq $_ } {
            $localOrgStructure.division = "People"
            switch ($orgCode) {
                "000905" { $localOrgStructure.department = "Operations"; break }
                "000906" { $localOrgStructure.department = "Talent Acquisition"; break }
            }
            $localOrgStructure.combined = "Ppl | $($localOrgStructure.department)"
            break
        }
        #revenue
        { "000201", "000204", "000205", "000206", "000209", "000701", "000702", "000705", "000706", "000707", "000710", "000711" -eq $_ } {
            $localOrgStructure.division = "Revenue"
            switch ($orgCode) {
                "000201" { $localOrgStructure.department = "Customer Success"; break }
                "000204" { $localOrgStructure.department = "Customer Success"; break }
                "000205" { $localOrgStructure.department = "Customer Support"; break }
                "000206" { $localOrgStructure.department = "Customer Success"; break }
                "000209" { $localOrgStructure.department = "Customer Success"; break }
                "000701" { $localOrgStructure.department = "Sales"; break }
                "000702" { $localOrgStructure.department = "Sales"; break }
                "000705" { $localOrgStructure.department = "Strategic Partnerships"; break }
                "000706" { $localOrgStructure.department = "Strategic Services"; break }
                "000707" { $localOrgStructure.department = "Pre-Sales"; break }
                "000710" { $localOrgStructure.department = "Business Development"; break }
                "000711" { $localOrgStructure.department = "Revenue Operations"; break }
            }
            $localOrgStructure.combined = "Rev | $($localOrgStructure.department)"
            break
        }

        #marketing
        { "000801", "000804", "000806", "000807", "000808" -eq $_ } {
            $localOrgStructure.division = "Marketing"
            switch ($orgCode) {
                "000801" { $localOrgStructure.department = "Demand Generation"; break }
                "000804" { $localOrgStructure.department = "Product Marketing"; break }
                "000806" { $localOrgStructure.department = "Strategic Solutions"; break }
                "000807" { $localOrgStructure.department = "Design & Creative"; break }
                "000808" { $localOrgStructure.department = "Syndication"; break }
            }
            $localOrgStructure.combined = "Mktg | $($localOrgStructure.department)"
            break
        }
        #product
        # { "000601", "000602", "000603" -eq $_ } {
        # $localOrgStructure.division = "Product"
        # switch ($orgCode) {
        # "000601" { $localOrgStructure.department = "Management & Design"; break }
        # "000602" { $localOrgStructure.department = "Management & Design"; break }
        # "000603" { $localOrgStructure.department = "Engagement & Analytics"; break }
        # }
        # $localOrgStructure.combined = "Pgs | $($localOrgStructure.department)"
        # break
        # }
        #engineering
        { "000502", "000503", "000506", "000507", "000508", "000509", "000907", "1000509", "000910", "000911", "000601", "000602", "000603" -eq $_ } {
            $localOrgStructure.division = "Engineering"
            switch ($orgCode) {
                "000502" { $localOrgStructure.department = "QA"; break }
                "000503" { $localOrgStructure.department = "Project Management"; break }
                "000910" { $localOrgStructure.department = "Project Management"; break }
                "000506" { $localOrgStructure.department = "Data & Strategy"; break }
                "000507" { $localOrgStructure.department = "Software Development"; break }
                "000508" { $localOrgStructure.department = "Information Security"; break }
                "000911" { $localOrgStructure.department = "Information Security"; break }
                "000509" { $localOrgStructure.department = "Software Development"; break }
                "000907" { $localOrgStructure.department = "IT"; break }
                "1000509" { $localOrgStructure.department = "Platform"; break }
                "000601" { $localOrgStructure.department = "Product & Design"; break }
                "000602" { $localOrgStructure.department = "Product & Design"; break }
                "000603" { $localOrgStructure.department = "Product & Design"; break }
            }
            $localOrgStructure.combined = "Eng | $($localOrgStructure.department)"
            break
        }
        #finance
        { "2000901", "3000901", "000908" -eq $_ } {
            $localOrgStructure.division = "Finance"
            switch ($orgCode) {
                "2000901" { $localOrgStructure.department = "FP&A"; break }
                "3000901" { $localOrgStructure.department = "Accounting"; break }
                "000908" { $localOrgStructure.department = "Legal"; break }
            }
            $localOrgStructure.combined = "Fin | $($localOrgStructure.department)"
            break
        }
        default {}
    }

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

    return $localOrgStructure
}