Trouble re-enabling scheduled jobs

Welcome Forums General PowerShell Q&A Trouble re-enabling scheduled jobs

This topic contains 2 replies, has 2 voices, and was last updated by

6 months, 4 weeks ago.

  • Author
  • #102644

    Points: 2
    Rank: Member

    I use this function to register a scheduled job. It runs fine until I disable it, and then re-enable it (Enable-ScheduledJob). They are shown as Enabled in Task Scheduler. What might I be missing here?
    (The credential below is the user name and I input the password when registering the job initially. This is also the admin)

    function Register-Execution{
    [datetime] $time,

    [string] $jobName,

    [string] $pathToScript
    $trigger = New-JobTrigger -Daily -At $time
    $options = New-ScheduledJobOption -RunElevated
    Register-ScheduledJob -Name $jobName -Trigger $trigger -Credential ".........." -FilePath $pathToScript

  • #102794

    Points: 0
    Rank: Member

    UPDATE j
    SET j.Enabled = 0
    FROM MSDB.dbo.sysjobs j
    INNER JOIN MSDB.dbo.syscategories c ON j.category_id = c.category_id
    WHERE c.[Name] = 'Database Maintenance';

    I haven't profiled it, but I suspect

    USE msdb ;

    EXEC dbo.sp_update_job
    @job_name = N'SomeJob',
    @enabled = 0;

    Will be generating the same code, but the builtin procs are usually the way to go.

  • #102905

    Points: 2
    Rank: Member

    Thanks. Still haven't given up on Powershell though, if only to know why it fails here.

The topic ‘Trouble re-enabling scheduled jobs’ is closed to new replies.