Public/Get-specSCFilteredData.ps1

Function Get-specSCFilteredData {
    <#
    .SYNOPSIS
    Filters table data based on specified DPGGroup and Location criteria.
 
    .DESCRIPTION
    The Get-specSCFilteredData function filters an input array of table data by evaluating combinations of 'DPGGroup' and 'Location' values.
    It returns rows that match any of the following:
    - DPGGroup equals the specified value and Location is 'ALL'
    - Both DPGGroup and Location match the specified values
    - DPGGroup and Location are both 'ALL'
    - DPGGroup is 'ALL' and Location matches the specified value
 
    This is useful for hierarchical or fallback matching logic in scenarios where 'ALL' serves as a wildcard or global scope.
 
    .PARAMETER tableData
    An array of objects representing the data table to filter. Each object must contain the properties 'DPGGroup' and 'Location'.
 
    .PARAMETER DPGGroup
    The DPG group value to filter the table data by.
 
    .PARAMETER Location
    The location value to filter the table data by.
 
    .OUTPUTS
    Array
    Returns an array of filtered objects that match the specified criteria.
 
    .EXAMPLE
    PS C:\> Get-specSCFilteredData -tableData $data -DPGGroup 'DPG001' -Location 'LON'
 
    Returns all rows from $data that match DPGGroup 'DPG001' and/or Location 'LON', according to the defined rules.
 
    .NOTES
        Author - owen.heaume
        Version - 1.0 Initial Release
                - 1.1 Optimise filter - replace switch with 'where' clause
    #>


    [cmdletbinding()]

    param(
        [array]$tableData,

        [string]$DPGGroup,
        [string]$Location,
        [string]$Device
    )

    begin {
        $finalData = @()
    }

    process {
        $finalData = $tableData | ? { # FILTER INFO:
            ($_.DPGGroup -eq $DPGGroup -and $_.Location -eq 'ALL' -and $_.Device -eq 'ALL') -or # DPGGroup only
            ($_.DPGGroup -eq $DPGGroup -and $_.Location -eq $Location -and $_.Device -eq 'ALL') -or # DpgGroup AND Persona
            ($_.DPGGroup -eq 'ALL' -and $_.Location -eq 'ALL' -and $_.Device -eq 'ALL') -or # All
            ($_.DPGGroup -eq 'ALL' -and $_.Location -eq $Location -and $_.Device -eq 'ALL') -or # Location only
            ($_.DPGGroup -eq 'ALL' -and $_.Location -eq 'ALL' -and $_.Device -eq $Device)              # Device only
        }
    }

    end {
        $finalData
    }
}