禁用多个计划任务 - PowerShell

Disable multiple scheduled tasks - PowerShell

我正在编写一个脚本来禁用 Windows 10 中的多个计划任务。这是我的尝试:

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

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

计划任务不存在时报错

如何解决? (没有 SilentlyContinue)

谢谢! :D

您的代码缺少 -TaskPath-TaskName

示例-任务名称

Disable-ScheduledTask -TaskName "SystemScan"

示例-任务路径

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

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

也许您的姓名哈希列表中间缺少斜杠。

示例 Get-ScheduledTask -TaskPath 列表

$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

}

示例 Get-ScheduledTask -TaskName 列表

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

ForEach($task in $tasks){

Disable-ScheduledTask -TaskName "$task"

}