I am working on creating a task to setup a Task Scheduler job on Windows machine. I have a script that register Task scheduler, when I run the script from Terraform Customscript extension it is not giving any error or creating the schedule Task. Though I have tried to wright the stdout to a file, command is not giving any output after execution.
I have tried to run the same command on by login to machine and able to create task successfully.
Powershell command script name “TaskScheduler.ps1”
#Setup Task scheduler echo "Settingup Schedule task" | Out-File -FilePath C:UsersScript_output.log -Append $taskTrigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek Friday -At 8pm $taskAction = New-ScheduledTaskAction -Execute "PowerShell" -Argument '-NoProfile -ExecutionPolicy Bypass -File "C:UsersBackupScriptsbackup.ps1"' -WorkingDirectory "C:UsersBackupScripts"
From Terraform I am executing the command as follow :
powershell.exe -ExecutionPolicy Bypass -File C:/Users/BackupScripts/TaskScheduler.ps1
Sandeep Reddy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.