PowerShell 7.3 - implementing Running Scheduled Tasks that Trigger a Script with Parameters
I've tried everything I can think of but I'm integrating two systems and I've been banging my head against this for hours... I'm having trouble getting a scheduled task to run a PowerShell script with parameters correctly when it's triggered. I've created a task using the `New-ScheduledTask` cmdlet and pointed it to a script that requires parameters. However, when the scheduled task runs, it seems to ignore the parameters, and I'm receiving the following behavior: `The term 'YourScript.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program.` Hereโs the code I used to create the scheduled task: ```powershell $Action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-File "C:\Path\To\YourScript.ps1" -Parameter1 value1 -Parameter2 value2' $Trigger = New-ScheduledTaskTrigger -AtStartup $Principal = New-ScheduledTaskPrincipal -UserId 'SYSTEM' -LogonType ServiceAccount Register-ScheduledTask -Action $Action -Trigger $Trigger -Principal $Principal -TaskName 'MyPowerShellTask' -Description 'Runs a PowerShell script with parameters' ``` I checked the path to the script, and itโs correct. If I run the script directly from PowerShell with the same parameters, it executes as expected. However, when the task runs, it either fails to find the script or doesn't pass the parameters. Iโve also tried modifying the argument portion to enclose the entire command in single quotes or escaping the quotes, but that hasnโt resolved the scenario. I've checked that the scheduled task is set to run with the highest privileges and that the account has access to the script. Has anyone experienced similar issues or have insights on how to correctly pass parameters to a PowerShell script via a scheduled task in PowerShell 7.3? My development environment is Linux. Any advice would be much appreciated. This is happening in both development and production on Linux. Any help would be greatly appreciated!