Skip to content

# milestone patch v3.0.1 - a5 #12

Description

@aj1126

milestone patch v3.0.1 - a5

5. Scheduled Task Syntax Error

File: src/MyBookTools.psm1

Function: Register-MyBookMaintenanceTask

Issue: Task registration fails with a syntax exception.

Root Cause: -At 3:00AM throws an error because PowerShell evaluates 3 as an integer, which cannot natively parse the AM string suffix without encapsulation.

Resolution:
Wrap the time argument in string quotes.

    switch ($Schedule) {
        'Daily' {
            $trigger = New-ScheduledTaskTrigger -Daily -At "3:00 AM"
        }
        'Hourly' {
            $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(5)
            $trigger.RepetitionInterval = 'PT1H'
            $trigger.RepetitionDuration = 'P1D'
        }
        default {
            $trigger = New-ScheduledTaskTrigger -Daily -At "3:00 AM"
        }
    }

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions