6

Does anyone know how to update the Arguments of a Scheduled Task Action using PowerShell?

Here is how I have been told to update the Action, thanks to @Richard 's answer in another question.

$Action = New-ScheduledTaskAction -Execute "PowerShell.exe"
Set-ScheduledTask -TaskName "YourTaskName" -Action $Action

What do I need to add to this so I can also change the Argument and I suppose whilst we are here, the Start In option as well?

Community
  • 1
  • 1
Gareth Doherty
  • 187
  • 1
  • 3
  • 15

1 Answers1

6

Use the -Argument parameters to add an argument string to an action. And use the -WorkingDirectory parameter to add a Start In option.

$Action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument 'Arg1 Arg2' -WorkingDirectory "C:\StartInThisFolder\"
Richard
  • 6,812
  • 5
  • 45
  • 60
  • Thanks again @Richard. I don't see why I can't find such simple information using google :P – Gareth Doherty Oct 10 '16 at 13:17
  • @GarethDoherty A hand trick is to use the `Help` cmdlet e.g. `help New-ScheduledTaskAction -full` will give you all the syntax. If you need a command and you dont know what its called can use `Get-command "*Task*"` This will get any cmdlets to do with tasks. – Richard Oct 10 '16 at 13:31
  • Sorry I am back again. `Set-ScheduledTask -TaskName "YourTaskName" -TaskPath "\ScheduledJobs\Non-Live\ -Action $Action` – Gareth Doherty Oct 12 '16 at 14:05
  • Sorry, I cannot amend that comment. but `Set-ScheduledTask -TaskName "YourTaskName" -TaskPath "\ScheduledJobs\Non-Live\" -Action $Action` why does I get and **The specified path is invalid.** The Task Path exists :( – Gareth Doherty Oct 12 '16 at 14:07
  • Create the Task manually in the location that you want it. Then run `Get-ScheduledTask` and look to see what the `TaskPath` is then use that. – Richard Oct 13 '16 at 07:02
  • Hi Richard, I raised another question for this here where I explain what I have done [link](http://stackoverflow.com/questions/40001457/update-scheduled-task-in-sub-folder-the-specified-path-is-invalid-powershell) – Gareth Doherty Oct 13 '16 at 07:25