PowerShell 7.3 - advanced patterns with Scheduled Task Trigger Configuration
I need help solving I'm refactoring my project and I'm trying to create a scheduled task in PowerShell 7.3 that runs a specific script daily at 3 PM. However, after configuring the trigger, the task seems to not follow the scheduled time correctly. Here's the code I'm using: ```powershell $Action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument '-File C:\Scripts\MyScript.ps1' $Trigger = New-ScheduledTaskTrigger -Daily -At '15:00' $Principal = New-ScheduledTaskPrincipal -UserId 'SYSTEM' -LogonType ServiceAccount $TaskSettings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopOnIdleEnd Register-ScheduledTask -Action $Action -Trigger $Trigger -Principal $Principal -TaskName 'MyDailyTask' -Description 'Runs my script daily at 3 PM' -Settings $TaskSettings ``` After I run this script, it appears to create the scheduled task successfully, but when I check the Task Scheduler GUI, the trigger is set to run at a different time, sometimes even at 12 AM instead of 3 PM. I've tried to explicitly set the time in various formats, but the result remains the same. Additionally, I'm running PowerShell as an administrator, and I've confirmed that the system time is correctly set. I also tried using `-At (Get-Date '15:00')` to see if that resolved the scenario, but it didn't help either. Has anyone encountered this scenario or have any ideas on what might be going wrong? Is there a possibility that there are permissions or system policy settings affecting the scheduled task configuration? I'm working on a application that needs to handle this. Any feedback is welcome! Is there a simpler solution I'm overlooking?