Hi Jeff,
This can be achieved with PrtgAPI. Whiile manipulation of schedule properties is not fully supported, this can still be achieved by combining a bit of PowerShell with the library's underlying C# API
As you've indicated, by enabling inheritance of schedule settings from the parent object, you will have effectively "disabled" the schedule for that object. The schedules can (theoretically) be re-added by disabling schedule inheritance again. The major challenge however (as Andreas alludes to) is that when you enable inheritance of schedule settings the original schedule will actually have been deleted!
The solution to this, therefore, is to perform the following
1. Save the original schedule of the object (if applicable)
2. Enable schedule inheritance (removing the schedule)
3. Disable schedule inheritance, re-adding the previously saved schedule
The following gives an example of how to do this to a single sensor (ID 7816)
$sensor = Get-Sensor -Id 7816
$schedule = ($sensor | Get-ObjectProperty).Schedule
$sensor | Set-ObjectProperty -RawProperty scheduledependency -RawValue 1
$p1 = New-Object PrtgAPI.Parameters.CustomParameter -ArgumentList @("schedule_", $schedule)
$p2 = New-Object PrtgAPI.Parameters.CustomParameter -ArgumentList @("scheduledependency", 0)
$ps = $p1,$p2
(Get-PrtgClient).SetObjectPropertyRaw($sensor.Id, $ps)
In your scenario, I would recommend building up a Dictionary mapping objects to schedules. Abstract the code out into two functions: one that gets rid of a schedule and one that restores it. When you are ready to re-enable your schedules again, you can simply iterate over the Dictionary, re-adding the specific schedule that belonged to each object.
Regards,
lordmilko
Add comment