I have the below script to disable the task scheduler job, which should disable the job if it is not disabled, but it exits the window without disabling , what am I missing here? Any thoughts?
if ((Get-ScheduledTask -taskname test | Select-Object -ExpandProperty State) -notmatch "disabled") { exit 1 }
Disable-ScheduledTask -taskname test