3

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.

3 Answers 3

4

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

1
  • 2
    Tried that - same thing.
    – Jonathan
    Commented Mar 16, 2017 at 15:07
0

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.

3
  • Yes, I tried refresh, also tried close&open task scheduler and restart entire machine. So you don't get repro? weird...
    – Jonathan
    Commented Feb 13, 2017 at 10:20
  • Yes, I am also on windows 10 64bit and I see "MyTask" running your code in the Task Scheduler Library folder.
    – Gravity
    Commented Feb 13, 2017 at 10:26
  • On my Win 10 Home 64-bit, your script works fine too and I could see the new task in the list, with Get-ScheduledTask or manually viewing the Task Scheduler Library. Commented Feb 13, 2017 at 13:28
0

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

1
  • 1
    Thanks - I am using Powershell. I don't have a Task Scheduler Library -> Microsoft -> Powershell -> Scheduled Jobs folder. Show Hidden Scheduled Tasks was always checked.
    – Jonathan
    Commented Feb 15, 2017 at 11:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.