1

PowerShell script doesn't run when using Start in (Optional) field.

I have simple PowerShell Script to create a task scheduler which schedule the task and job will run the bat file. I was able to create the task but I have to add the path @ Start in (optional) field. I was able to add the path in Add arguments but not finding the details how can I add the file path to Start in.

$Trigger= New-ScheduledTaskTrigger -At 10:00am -Once
$User= "username"
$Action= New-ScheduledTaskAction -Execute "full BAT file location\123.bat" -Argument "bat file location"
Register-ScheduledTask -TaskName "BAT Task" -Trigger $Trigger -User $User -Action $Action -RunLevel Highest –Force

When I run the PS script it should add the details in Start in field.

1 Answer 1

0

You should just need to update your $Action variable by adding the -WorkingDirectory parameter:

$Action= New-ScheduledTaskAction -Execute "full BAT file location\123.bat" `
-Argument "bat file location" -WorkingDirectory "Start In Path"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.