简体   繁体   English

使用Powershell脚本在任务计划程序中启用/禁用任务

[英]Enabling / Disabling tasks in Task Scheduler using a Powershell script

I am trying to disable a task in the Windows task scheduler using PowerShell. 我正在尝试使用PowerShell在Windows任务计划程序中禁用任务。 How can I do this? 我怎样才能做到这一点?

$tasks = & SCHTASKS /Query /V /FO CSV | ConvertFrom-Csv
$task = $tasks | ? { $_.TaskName -eq "E:\MyDir\test.bat" }  
& SCHTASKS /Change /DISABLE /TN "$Task.TaskName"

This error is the result: 结果是此错误:

ERROR: The specified task name ".TaskName" does not exist in the system. 错误:指定的任务名称“ .TaskName”在系统中不存在。

“ $($ task.Taskname)”应该起作用。

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

相关问题 如何在静默/隐藏模式下使用任务调度程序运行powershell脚本? - How to run powershell script using task scheduler in silent/hidden mode? 在Windows 7中启用/禁用任务 - Enabling/Disabling a task in Windows 7 Powershell脚本运行任务计划程序将无法启动Photoshop - Powershell script run task scheduler will not start photoshop 使用任务计划程序计划的Powershell脚本无法运行…脚本运行正常 - Powershell script scheduled using Task scheduler doesn't run…script runs fine 使用Windows Task Scheduler运行的PowerShell脚本未运行SQL Server SSIS DTEXEC.EXE作业 - PowerShell script run using Windows Task Scheduler is not running a SQL Server SSIS DTEXEC.EXE job Powershell Monitor任务计划程序 - Powershell monitor task scheduler 在任务计划程序中运行PowerShell - Running PowerShell in Task Scheduler 阅读通过任务计划程序运行的隐藏 powershell 脚本的内容 - Read the contents of a hidden powershell script running trough Task Scheduler 在Windows Task Scheduler中以其他用户身份运行的PowerShell脚本 - PowerShell script running as different user in Windows Task Scheduler Windows 任务计划程序中的 PowerShell 脚本无法正常工作 - PowerShell script doesn't work correctly from Windows Task Scheduler
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM