Public/Get-SDPAnnouncement.ps1

function Get-SDPAnnouncement {
    <#
    .SYNOPSIS
        Retrieves one or more announcements from ServiceDesk Plus.
    .PARAMETER Id
        The ID of the announcement to retrieve.
    .PARAMETER PageSize
        Number of records per page (1–100). Defaults to 100.
    .PARAMETER StartIndex
        1-based starting index for the page. Defaults to 1.
    .PARAMETER All
        Automatically pages through all results.
    .EXAMPLE
        Get-SDPAnnouncement -Id '5'
    .EXAMPLE
        Get-SDPAnnouncement -All
    #>

    [CmdletBinding(DefaultParameterSetName = 'List')]
    [OutputType('SDPAnnouncement')]
    param(
        [Parameter(Mandatory, ParameterSetName = 'Id', ValueFromPipelineByPropertyName)]
        [string]$Id,

        [Parameter(ParameterSetName = 'List')]
        [ValidateRange(1, 100)]
        [int]$PageSize = 100,

        [Parameter(ParameterSetName = 'List')]
        [int]$StartIndex = 1,

        [Parameter(ParameterSetName = 'List')]
        [switch]$All
    )

    process {
        if ($PSCmdlet.ParameterSetName -eq 'Id') {
            $response = Invoke-SDPRestMethod -Endpoint "announcements/$Id"
            [SDPAnnouncement]::new($response.announcement)
            return
        }

        $listInfo = @{ row_count = $PageSize }

        if ($All) {
            $index = $StartIndex
            do {
                $listInfo['start_index'] = $index
                $response = Invoke-SDPRestMethod -Endpoint 'announcements' -InputData @{ list_info = $listInfo }
                foreach ($a in $response.announcements) { [SDPAnnouncement]::new($a) }
                $index += $PageSize
            } while ($response.list_info.has_more_rows)
        } else {
            $listInfo['start_index'] = $StartIndex
            $response = Invoke-SDPRestMethod -Endpoint 'announcements' -InputData @{ list_info = $listInfo }
            foreach ($a in $response.announcements) { [SDPAnnouncement]::new($a) }
        }
    }
}