0

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.

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

4 Comments

thanks!! that worked. But it's asking me for my windows user password for disabling. Is there a way we can disable a task without the script asking for the password?
Run the script with an elevated console?
could you please elobarate as to what "elevated console" means?
"Run as Administrator" is what @SpellingD meant.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.