user1411254
user1411254

Reputation: 139

Enabling / Disabling tasks in Task Scheduler using a Powershell script

I am trying to disable a task in the Windows task scheduler using PowerShell. 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.

Upvotes: 0

Views: 3769

Answers (1)

Mike Shepard
Mike Shepard

Reputation: 18176

"$($task.Taskname)" should work.

Upvotes: 3

Related Questions