Jonathan
Jonathan

Reputation: 7561

Scheduled task created in Powershell doesn't appear in Task Scheduler

I'm creating a schedule task in Powershell, like this:

$action = New-ScheduledTaskAction -Execute cmd.exe -Argument "-c echo %date% %time% >d:\test.txt"
$trigger = New-ScheduledTaskTrigger -Once -At 12am
#$principal = New-ScheduledTaskPrincipal -UserId $env:userdomain\$env:username
$task = New-ScheduledTask -Action $action -Trigger $trigger
$task | Register-ScheduledTask -TaskName MyTask

The task gets registered: It runs (verified via its output to d:\test.txt), and I can also see it in a separate Powershell window:

PS D:\temp> Get-ScheduledTask MyTask | fl

Actions            : {MSFT_TaskExecAction}
Author             :
Date               :
Description        :
Documentation      :
Principal          : MSFT_TaskPrincipal2
SecurityDescriptor :
Settings           : MSFT_TaskSettings3
Source             :
State              : Ready
TaskName           : MyTask
TaskPath           : \
Triggers           : {MSFT_TaskTimeTrigger}
URI                : \MyTask
Version            :
PSComputerName     :

However, when I open Task Scheduler, I don't see my task in there anywhere - it should be in the Task Scheduler Library folder. I've created a task manually in Task Scheduler, and it looks the same in Get-ScheduledTask.

Why isn't my task seen in Task Scheduler?
How can I create a Task in Powershell so it is seen?

Edit:: I'm on Windows 10 64-bit, Anniversary Update.

Upvotes: 3

Views: 6845

Answers (3)

Mari Bergström
Mari Bergström

Reputation: 51

Run Task Scheduler as Administrator and you'll see more tasks.

Upvotes: 5

Murat
Murat

Reputation: 61

I had a similar issue and my task was under Task Scheduler Library -> Microsoft -> Powershell -> Scheduled Jobs.

Since you don't appear to be using powershell I'd check all of the folders under Task Scheduler Library to see where it is.

I'd also right click Task Scheduler Library and check View -> Show Hidden Scheduled Tasks

Upvotes: 0

Gravity
Gravity

Reputation: 11

Your code is working properly.

Did you tried to refresh your task scheduler using F5 ?

If you have opened the task scheduler before executing, the task doesn't appears. You need to refresh using F5 or right-click (on the folder) -> refresh.

Upvotes: 0

Related Questions