简体   繁体   中英

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.

以管理员身份运行Task Scheduler,您将看到更多任务。

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM