Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update a Scheduled Task Action Argument using Powershell 4.0

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?

like image 314
Gareth Doherty Avatar asked Oct 10 '16 11:10

Gareth Doherty


People also ask

Can we schedule PowerShell script?

Microsoft Windows Task Scheduler can run PowerShell scripts, but to do so you will first need to specify it as an argument to PowerShell. Hopefully this article will help you automate many of your daily activities on your Windows system.


1 Answers

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\"
like image 110
Richard Avatar answered Oct 06 '22 08:10

Richard