PowerShell 7.3 - implementing Scheduled Task Trigger Not Firing as Expected with Custom Script
I'm reviewing some code and I'm having trouble with a scheduled task in PowerShell 7.3 that I've set up to run a custom script at a specific time... I configured the task using the `New-ScheduledTask` cmdlet, but it doesn't seem to trigger the script at the scheduled time. I verified the task is created using `Get-ScheduledTask`, and it shows the correct settings. However, when the time comes, I don't see any output or logs from the script. Hereโs the code I've used to create the scheduled task: ```powershell $action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument '-File "C:\Scripts\MyScript.ps1"' $trigger = New-ScheduledTaskTrigger -At '11:00AM' -Daily $principal = New-ScheduledTaskPrincipal -UserId 'NT AUTHORITY\SYSTEM' -LogonType ServiceAccount Register-ScheduledTask -Action $action -Trigger $trigger -Principal $principal -TaskName 'MyCustomTask' ``` I checked the Task Scheduler, and it shows the task is enabled. I also tried running the script manually, and it works perfectly fine. Furthermore, I have ensured that the script does not require any user interaction. I suspect there might be an scenario with permissions or the context in which the script runs. Iโve tried changing the user for the scheduled task to my own account, but that didnโt seem to help either. The Windows Event Viewer does not show any errors related to this task either. Can someone shed light on what could be going wrong? Is there a way to debug if the task is firing or check its exit code? Any help would be greatly appreciated! Any ideas what could be causing this?