Dashboard last run scheduled jobs

Hey All,

I’m trying to create a simple dashboard with table that shows scheduled scripts name, description, last run and result. Seems easy but couple things are not pulling correctly. I wrote the script below but on the table I cannot see the status of the job correctly and the last run shows as a different format than when I see it in powershell itself.

Here is the script I’m using

$schedules = Get-PSUSchedule

$results = @()
foreach ($schedule in $schedules) {
# Get the latest job associated with the schedule
$job = Get-PSuJob -Script $schedule.Script | Select-Object -First 1
# Check if a job exists for the schedule
if ($job) {
# Create a new object to store schedule and job information
$myObj = New-Object PSObject -Property @{
Name = $schedule.Name
Scheduling = $schedule.Description
LastRun = $job.EndTime
# Access and format the desired result value based on what’s available
Result = $job.Status
}
# Add the populated object to the results array
$results += $myObj
} else {
# Handle cases where no job is found for the schedule
Write-Warning “No job found for schedule ‘$schedule.Name’.”
}
}

Display or export the results as needed

$results

Product: PowerShell Universal
Version: 4.2.2