简体   繁体   English

在Powershell中创建的计划任务未出现在Task Scheduler中

[英]Scheduled task created in Powershell doesn't appear in Task Scheduler

I'm creating a schedule task in Powershell, like this: 我正在Powershell中创建一个计划任务,如下所示:

$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: 任务已注册:它运行(通过输出到d:\\ test.txt进行验证),我也可以在单独的Powershell窗口中看到它:

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. 但是,当我打开Task Scheduler时,在任何地方都看不到我的任务-它应该在Task Scheduler Library文件夹中。 I've created a task manually in Task Scheduler, and it looks the same in Get-ScheduledTask . 我已经在Task Scheduler中手动创建了一个任务,在Get-ScheduledTask看起来也一样。

Why isn't my task seen in Task Scheduler? 为什么在任务计划程序中看不到我的任务?
How can I create a Task in Powershell so it is seen? 如何创建PowerShell中的任务,因此视为?

Edit: : I'm on Windows 10 64-bit, Anniversary Update. 编辑::我在Windows 10 64位,周年更新。

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

Your code is working properly. 您的代码正常工作。

Did you tried to refresh your task scheduler using F5 ? 您是否尝试过使用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. 您需要使用F5刷新或右键单击(在文件夹上)->刷新。

I had a similar issue and my task was under Task Scheduler Library -> Microsoft -> Powershell -> Scheduled Jobs. 我遇到了类似的问题,我的任务在任务计划程序库-> Microsoft-> Powershell->计划的作业下。

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. 由于您似乎没有使用Powershell,因此我将检查Task Scheduler库下的所有文件夹以查看其位置。

I'd also right click Task Scheduler Library and check View -> Show Hidden Scheduled Tasks 我还要右键单击“任务计划程序库”,然后选中“查看”->“显示隐藏的计划任务”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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