Public/Get-FSvcTicketOverview.ps1

function Get-FSvcTicketOverview {
    <#
    .SYNOPSIS
        Three-list triage: unassigned, waiting on customer, awaiting agent.
    .DESCRIPTION
        Returns one object per ticket with a Category property, so pipe it to
        Where-Object / Group-Object / Format-Table. Rows are grouped in report
        order (unassigned, waiting, awaiting_agent) and, within each group,
        ordered by Days descending (longest-waiting first). Each row exposes the
        numeric business-day count (Days) plus a humanized Elapsed ("13d 14h", or "1h 30m" below a day)
        and the Since timestamp the count is measured from (created_at for
        unassigned rows, the last message otherwise). Unanswered is the number
        of customer messages the agent has not answered yet (consecutive
        incoming messages since the last agent message); it is $null for
        unassigned rows, which are not fetched conversation by conversation.
    .EXAMPLE
        Get-FSvcTicketOverview -OlderThanDays 2 | Format-Table Category, Id, Subject, Days
    #>

    [CmdletBinding()]
    param(
        [string]$UnassignedQueryHash,
        [string]$AssignedQueryHash,
        [double]$OlderThanDays = 2,
        [int]$PerPage = 100
    )
    $cfg = Get-FSvcEffectiveConfig
    $now = [datetimeoffset]::Now

    $out = @()
    $unassigned = Get-FSvcTargetTickets -View Unassigned -QueryHash $UnassignedQueryHash -PerPage $PerPage -Config $cfg
    foreach ($t in @($unassigned)) {
        $created = ConvertTo-FSDateTimeOffset $t.created_at
        $days = 0.0
        if ($null -ne $created) { $days = Get-FSvcBusinessDaysBetween -From $created -To $now }
        $out += New-FSvcOverviewRow -Category 'unassigned' -Ticket $t -RawDays $days -Since $created -Unanswered $null -BaseUrl $cfg.BaseUrl
    }

    $assigned = Get-FSvcTargetTickets -View SelfAssigned -QueryHash $AssignedQueryHash -PerPage $PerPage -Config $cfg
    foreach ($t in @($assigned)) {
        $thread = Get-FSvcTicketThread -TicketId $t.id -Config $cfg
        $triage = Get-FSvcTriage -Ticket $t -LatestConversation $thread.Latest -OlderThanDays $OlderThanDays -Now $now
        if ($null -eq $triage) { continue }
        $out += New-FSvcOverviewRow -Category $triage.Category -Ticket $t -RawDays $triage.Days -Since $triage.Since -Unanswered $thread.Unanswered -BaseUrl $cfg.BaseUrl
    }
    return (Sort-FSvcOverviewRows -Rows $out)
}