Trouble re-enabling scheduled jobs

This topic contains 2 replies, has 2 voices, and was last updated by  Emil Tanev 4 weeks ago.

  • Author
    Posts
  • #102644

    Emil Tanev
    Participant

    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)
    Thanks

    function Register-Execution{
    [CmdletBinding()]
    param(
    [Parameter(Mandatory=$true)]
    [datetime] $time,

    [Parameter(Mandatory=$true)]
    [string] $jobName,

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

  • #102794

    daniel
    Participant

    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 ;
    GO

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

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

  • #102905

    Emil Tanev
    Participant

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

You must be logged in to reply to this topic.