Assets/Get-OpsJobLog.ps1

<#
.SYNOPSIS
    Gets the recent transcript log files for Ops Jobs.
.PARAMETER JobName
    Optional specific job name. Supports wildcards.
.PARAMETER Count
    Number of recent logs to return.
#>

param (
    [string]$JobName = "*",
    [ValidateRange(1, [int]::MaxValue)]
    [int]$Count = 5
)

# The Ops root defaults to C:\Ops. OPS_ROOT overrides it for development and
# testing, matching the dashboard server's existing convention.
$OpsRoot = if ([string]::IsNullOrWhiteSpace($env:OPS_ROOT)) { "C:\Ops" } else { $env:OPS_ROOT }
$LogDir = Join-Path $OpsRoot "Logs"
if (-not (Test-Path -Path $LogDir)) {
    return @()
}

return @(Get-ChildItem -Path $LogDir -Filter "$JobName-*.log" -File -ErrorAction SilentlyContinue |
    Sort-Object LastWriteTime -Descending |
    Select-Object -First $Count)