0

I am trying to run a batch file from powershell, the script should run every 1 of the month.

But what this does is, it runs the batch file regardless of the time given.

I'm totally new to powershell so can't figure it out.

$trigger= New-ScheduledTaskTrigger -At 04:26pm –Daily # Specify the trigger settings

$action = Start-Process -FilePath C:\Users\xxx\abc.bat -Wait -passthru;$a.ExitCode

Register-ScheduledTask -Action $action -Trigger $trigger 
henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
  • 1
    Possible duplicate of [Powershell - Monthly Scheduled Task Trigger](https://stackoverflow.com/questions/34799923/powershell-monthly-scheduled-task-trigger) –  Dec 14 '18 at 11:58

2 Answers2

0

this example is from https://www.verboon.info/2013/12/powershell-creating-scheduled-tasks-with-powershell-version-3/

the action is not Start-Process but New-ScheduledTaskAction

$TaskAction = New-ScheduledTaskAction -Execute "$TaskCommand" -Argument "$TaskArg" 
$TaskTrigger = New-ScheduledTaskTrigger -At $TaskStartTime -Once
Register-ScheduledTask -Action $TaskAction -Trigger $Tasktrigger -TaskName "$TaskName" -User "System" -RunLevel Highest
Guenther Schmitz
  • 1,955
  • 1
  • 9
  • 23
0

There is a great answer here it shows you how to create a job to run daily, weekly or monthly in Powershell. Running monthly is a little more difficult as Powershell doesn't have a parameter option for monthly.

Tourius
  • 31
  • 1
  • 9