How to pause schedule on dashboard switch click

Product: PowerShell Universal
Version: 2.6.1

Looking through the docs, I don’t see a way to programmatically disable a schedule. Wondering if this is possible and what cmdlet I can use. Thanks!

Edit: Found a command to get the schedule, but no command that will allow me to make alterations… i.e. pause.

I think you’ll need to use the REST API directly. Check out the /api/v1/schedule PUT on the swagger documentation.

It might be something like this

Invoke-RestMethod http://localhost:5000/api/v1/schedule -METHOD Put -Body (@{
    Id = 123
    Paused = $true
} | ConvertTo-Json) -Headers @{ Authorization = "Bearer $AppToken" }

In case somebody else stumbled over this post, here is a working solution (obviously you want to ideally put everything in a try/catch). :wink:

# store your AppToken here
$AppToken = "myAppToken"

# get all schedules
$schedules = Get-PSUSchedule -ComputerName myServer -AppToken $AppToken

# parse them and take the right one you'd like to modify
foreach ($schedule in $schedules)
{
    if ($schedule.Name -eq "The name of the schedule I want to modify")
    {
        # Set the schedule to pause
        $schedule.Paused = $false

        # Convert the schedule to Json
        $scheduleJson = $schedule | ConvertTo-Json
        
        # Finally update the schedule
        Invoke-RestMethod "http://myServer:5000/api/v1/Schedule/$($schedule.id)" -METHOD Put -Body $scheduleJson -Headers @{
        "Authorization" = "Bearer $AppToken"
        "Content-Type" = "application/json"
        }
    }
}

@adam It might be helpful to have a Set-PSUSchedule cmdlet as well to make everything easier I think. But obviously doing it via REST API works as well… So the suggestion is just to make it a bit more neat and easy to use. :wink:

Kind regards,
Don

2 Likes