1 vote
We're having an issue with empty or near empty job histories on some of our more aggresive scripts that run multiple times every hour even though we have the default setting of 100 max history on every job.
This issue seems to be on scripts that run many times every day and have a lot of jobs being archived by a custom trigger based on the amount of work done in the script.
My best guess is that PSU is including archived jobs in the calculation when deciding how many jobs to archive since scripts that don't run as often and don't have a lot jobs archived by our custom trigger don't seem to be affected.
This is our custom archive trigger script:
param ($Job)
#$DebugPreference = "Continue"
$jobId = $Job.Id
if ([string]::IsNullOrEmpty($jobId))
{
Write-Error "No job id supplied."
}
Write-Information "$jobId - $($Job.Script.Name) ran by $($Job.Identity.Name) @ $($Job.StartTime) for $(($Job.EndTime - $Job.StartTime).TotalSeconds) seconds."
if (!$Job.Schedule)
{
Write-Information "Job is not scheduled - aborting."
return
}
$output = Get-PSUJobPipelineOutput -JobId $jobId -Integrated #-AppToken $apiToken.Token
$HostOutput = Get-PSUJobOutput -JobId $jobId -Integrated
if ($HostOutput)
{
Write-Information "[Job Output]"
Write-Information ($HostOutput -join [Environment]::NewLine)
Write-Information "[/Job Output]"
}
if ($output.Archive -eq $true)
{
# Archieve job
$apiToken = Get-PSUAppToken -Identity "JobArchiver" -Integrated | Where-Object -Property Revoked -Eq $false | Select-Object -ExpandProperty Token -First 1
if (!$apiToken)
{
Write-Error "Failed to retrieve api token!"
return
}
Write-Host "Archiving job.. " -NoNewLine
$response = Invoke-RestMethod -Uri "https://localhost/api/v1/job/archive/$jobId" -Method "DELETE" -SkipCertificateCheck -Headers @{
Authorization="Bearer $apiToken"
}
if($response.Archived)
{
Write-Host "✅ OK" -ForegroundColor Green
}
else {
Write-Host "Not archived?" -BackgroundColor Red
}
}
Write-Debug "Triggered by job:"
Write-Debug ($Job | ConvertTo-Json -WarningAction Ignore)Hello,
Thank you for the detailed report and for sharing your archive trigger script.
Your theory is reasonable, and we are treating it as the leading hypothesis.
We have not yet confirmed whether archived jobs count toward the Max Job History limit of 100.
If they do, a script that archives most of its runs would leave only a few visible jobs.
To confirm this, could you tell us which PowerShell Universal version you run?
Could you also tell us which database you use (SQLite, SQL Server, or PostgreSQL)?
For one affected script, please tell us how many jobs you expect to see and how many are visible now.
Please also check Settings > Data and tell us the server-wide job retention duration.
Meanwhile, you can raise Max Job History on the affected scripts, for example to 500.
If our theory is right, this should leave more visible jobs between archive runs.
Please let us know if that changes what you see.
Best regards,
Patrick Ouimet
We're running 2026.1.3
on SQL Server,
for one affected script that runs every 15 minutes I would expect to see 100 jobs in the history, currently only seeing 9, another is running every minute and I only see one job in the history (should be 100)
Data Retention is set to 180 days
I have changed the script with 1 job to 500 max history, will let you know the result :)
We do see more logs now, about 11 yesterday but it's down to 6 today - jobs we would expect to retain are still being removed.
Hello,
Thank you for the detailed numbers, which confirmed your theory.
Max Job History keeps the newest jobs for each script, and archived jobs count toward that total.
Jobs outside that window are deleted, archived or not.
For your every-minute script, 500 jobs cover only about 8 hours of runs, so you see just the few runs in that window that did work.
We reproduced this on 2026.1.3 and 2026.3.3, so an upgrade will not change it.
As a workaround, set Max Job History to the runs per day times the days you want to keep, for example, 10,080 for 7 days on the every-minute script.
This adds rows to the Job table, so please watch the database size.
The setting is described here: https://docs.devolutions.net/powershell-universal/automation/scripts
We are moving this thread to the PowerShell Universal Feature Request section so our development team can review leaving archived jobs out of the count.
Best regards,
Patrick Ouimet