Share via

Problem with managment task scheduller with power shell

2024-01-16T05:08:24.6733333+00:00
Hi. I made simple script, that shall change priority of scheduled task. It looks like this:

 

        $taskObj = Get-ScheduledTask -TaskName $task.TaskName | Select-Object -First 1 

        $OldState = $taskObj.State 

          

        $task.Settings.Priority = $priority 

 

        Set-ScheduledTask -User $user -Password $password -InputObject $task 

And it works fine with, but i keep getting errors only on tasks with mounthly triggers, error massage looks like this:

Set-ScheduledTask : Параметр задан неверно. 

D:\testiii\prior1.ps1:40 знак:9 

+         Set-ScheduledTask -User $user -Password $password -InputObjec ... 

+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

    + CategoryInfo          : InvalidArgument: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Set-ScheduledTask], CimException 

    + FullyQualifiedErrorId : HRESULT 0x80070057,Set-ScheduledTask 

No issues on tasks with weakly or daily triggers.

Could not find solution anywhere 
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2024-01-16T06:54:58.7933333+00:00

    Hi Никита Сухоруков ,

    Please check to see if this works.

    $task = Get-ScheduledTask -TaskName $TaskName
    $settings = $task.Settings
    $settings.Priority=1
    Set-ScheduledTask -TaskName $TaskName -Settings $settings
    

    Best Regards,

    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.