Import json on schedule being weird

Not sure how to get this to work quite right… I’m taking a json file and trying to get it to update every 5 minutes, so I have two scheduled tasks that creates the file, every 5 minutes and another task that resets the dashboard once a day (I did this so I could troubleshoot/ but json creation is fine). The only way I can get it to update the dashboard is by manually running the ps1. If I run the scheduled task normally, powershell -file / or & -Command expire.dash, then it returns error code 0 …(like it works). But the data shows the same as before. If I just get-content … the json looks fine / up-to-date. Currently, it only shows what I last ran manually/ wish I could get it to update either by scheduled task… or on file update.

code:
Import-Module UniversalDashboard.Community -Verbose

$data= Get-Content C:\Support\expiry.json|ConvertFrom-Json

$Schedule = New-UDEndpointSchedule -Every 5 -Minute
$Endpoint = New-UDEndpoint -Schedule $Schedule -Endpoint {
$Cache:Json = $data
}

Get-UDDashboard|where {$_.port -eq “10012”}|Stop-UDDashboard

$data=$data| Sort-Object RemainingDays,ExpiryDate
$dashboard= New-UDDashboard -Title ‘Stuff.com’ -Content {
New-UDGrid -Title “Expiring Users” -Headers @(“Name”, “ExpiryDate”, “RemainingDays”) -Properties @(“Name”, “ExpiryDate”, “RemainingDays”) -Endpoint {
$data | Out-UDGridData -TotalItems $data.Count
} -ServerSideProcessing -NoPaging -AutoRefresh
}

Start-UDDashboard -Dashboard $dashboard -Port 10012 -ErrorAction SilentlyContinue -Verbose -AutoReload -Endpoint $Endpoint

Try using the $Cache:Json variable in your grid. Also, make sure to update the cache variable in your scheduled endpoint.

Import-Module UniversalDashboard.Community -Verbose

$Cache:Json = Get-Content C:\Support\expiry.json|ConvertFrom-Json

$Schedule = New-UDEndpointSchedule -Every 5 -Minute
$Endpoint = New-UDEndpoint -Schedule $Schedule -Endpoint {
$Cache:Json = Get-Content C:\Support\expiry.json|ConvertFrom-Json
}

Get-UDDashboard|where {$_.port -eq “10012”}|Stop-UDDashboard

$data=$data| Sort-Object RemainingDays,ExpiryDate
$dashboard= New-UDDashboard -Title ‘[Stuff.com](http://stuff.com/)’ -Content {
New-UDGrid -Title “Expiring Users” -Headers @(“Name”, “ExpiryDate”, “RemainingDays”) -Properties @(“Name”, “ExpiryDate”, “RemainingDays”) -Endpoint {
$Cache:Json | Out-UDGridData -TotalItems $Cache:Json.Count
} -ServerSideProcessing -NoPaging -AutoRefresh
}
1 Like