our company has been having some issues with a new software's interaction with an existing task in task scheduler, so I wrote a small powershell script to run to set everything to the desired settings. Everything is working as intended except this snippet where I am trying to either remove or disable the log-on trigger attached to the task. I am able to get all the information about the trigger, but am not able to change anything about the trigger.
These are the snippets of what I have tried
$taskName = 'TEST'
$triggerToDelete = 1
$computerName = "LAPTOP"
$TaskScheduler = New-Object -com("Schedule.Service")
$TaskScheduler.Connect()
$TaskFolder = $TaskScheduler.GetFolder("\")
$Task = $TaskFolder.GetTask($taskName)
$Triggers = $Task.Definition.Triggers
$FirstTrigger = $Triggers.Item(1)
# get task definition and change it:
$definition = $task.Definition
$definition.Triggers.Item(1).enabled = $false
`$Task = Get-ScheduledTask -TaskName 'TEST'
$Trigger = $Task.Triggers[0]
$Trigger.Enabled = $false
$Trigger
Both ways end up showing like it has been disabled, but it continues to show "Enabled" in Task Scheduler, and triggers as normal.
Enabled : False EndBoundary : ExecutionTimeLimit : Id : Repetition : MSFT_TaskRepetitionPattern StartBoundary : 2023-09-13T19:00:00 DaysInterval : 1 RandomDelay : PSComputerName :