Home > Software engineering >  Disable multiple scheduled tasks - PowerShell
Disable multiple scheduled tasks - PowerShell

Time:12-04

I'm working on a script that disables multiple Scheduled Tasks in Windows 10. This is my attempt:

$TasksToDisable = @(
    ""
    ""
    ""
    )

Foreach ($Task in $TasksToDisable) {
    Get-ScheduledTask $Task | Disable-ScheduledTask
}

It gives me an error when a scheduled task does not exist.

How to solve this? (without SilentlyContinue)

Thank you! :D

CodePudding user response:

Your code is missing the -TaskPath or -TaskName

Example -TaskName

Disable-ScheduledTask -TaskName "SystemScan"

Example -TaskPath

Get-ScheduledTask -TaskPath "\UpdateTasks\" | Disable-ScheduledTask

Microsoft Disable-ScheduledTask Webpage https://docs.microsoft.com/en-us/powershell/module/scheduledtasks/disable-scheduledtask?view=windowsserver2019-ps

Maybe your hash list of names is missing slashes in-between.

Example Get-ScheduledTask -TaskPath List

$tasks = Get-ScheduledTask | Select TaskPath | Where {($_.TaskPath -like "*Active Directory Rights Management Services Client*")}
$tasks

ForEach($task in $tasks){

Get-ScheduledTask -TaskPath "$task" | Disable-ScheduledTask

}

Example Get-ScheduledTask -TaskName List

$tasks = Get-ScheduledTask | Select TaskName | Where {($_.TaskName -like "*AD*")}
$tasks

ForEach($task in $tasks){

Disable-ScheduledTask -TaskName "$task"

}

  • Related