Hi,<\/p>\n
I have set up a scheduled task to run a powershell script Test.ps1. This script is meant to run three other powershell Scripts one by one in a powershell script e.g<\/p>\n
‘C:\\Users\\WP\\Desktop\\Scripts\\1.ps1’<\/p>\n
‘C:\\Users\\WP\\Desktop\\Scripts\\2.ps1’<\/p>\n
‘C:\\Users\\WP\\Desktop\\Scripts\\3.ps1’<\/p>\n
I have scheduled the task as under:<\/p>\n
Program/script: C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe<\/p>\n
Add argruments: -noprofile -executionpolicy unrestricted -noninteractive -file “'C:\\Users\\WP\\Desktop\\Scripts\\Test.ps1”<\/p>\n
The task runs without error, return 0. But the ps script wasn’t executed. It works fine when I run it manually. Any inputs?<\/p>","upvoteCount":2,"answerCount":4,"datePublished":"2018-05-05T06:56:20.000Z","author":{"@type":"Person","name":"shobanasivalingam","url":"https://community.spiceworks.com/u/shobanasivalingam"},"suggestedAnswer":[{"@type":"Answer","text":"
Hi,<\/p>\n
I have set up a scheduled task to run a powershell script Test.ps1. This script is meant to run three other powershell Scripts one by one in a powershell script e.g<\/p>\n
‘C:\\Users\\WP\\Desktop\\Scripts\\1.ps1’<\/p>\n
‘C:\\Users\\WP\\Desktop\\Scripts\\2.ps1’<\/p>\n
‘C:\\Users\\WP\\Desktop\\Scripts\\3.ps1’<\/p>\n
I have scheduled the task as under:<\/p>\n
Program/script: C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe<\/p>\n
Add argruments: -noprofile -executionpolicy unrestricted -noninteractive -file “'C:\\Users\\WP\\Desktop\\Scripts\\Test.ps1”<\/p>\n
The task runs without error, return 0. But the ps script wasn’t executed. It works fine when I run it manually. Any inputs?<\/p>","upvoteCount":2,"datePublished":"2018-05-05T06:56:20.000Z","url":"https://community.spiceworks.com/t/powershell-script-not-running-from-scheduled-task/649971/1","author":{"@type":"Person","name":"shobanasivalingam","url":"https://community.spiceworks.com/u/shobanasivalingam"}},{"@type":"Answer","text":"
First question, does the account used to run the scheduled task have access to the path C:\\Users\\WP\\Scripts?<\/p>","upvoteCount":0,"datePublished":"2018-05-07T14:04:29.000Z","url":"https://community.spiceworks.com/t/powershell-script-not-running-from-scheduled-task/649971/2","author":{"@type":"Person","name":"christopherrobinson3","url":"https://community.spiceworks.com/u/christopherrobinson3"}},{"@type":"Answer","text":"
The problem lies with the -file parameter. What you need to do is just the following: -File Test.ps1 and then in the scheduled task, change the Start In to C:\\Users\\WP\\Desktop\\Scripts. For whatever reason powershell does not accept full paths in File, just a singular file. <\/p>","upvoteCount":0,"datePublished":"2018-09-26T14:00:14.000Z","url":"https://community.spiceworks.com/t/powershell-script-not-running-from-scheduled-task/649971/3","author":{"@type":"Person","name":"nerdyface","url":"https://community.spiceworks.com/u/nerdyface"}},{"@type":"Answer","text":"
This is factually incorrect.
\nI run numerous scheduled tasks using -file \\server\\share\\folder\\filename.ps1 and have no issues.
\nI don’t use the Start In option.<\/p>\n
Have you tested without some of the configuration options?
\nWhat happens if you manually execute the scheduled task without the -noprofile and -noninteractive parameters?<\/p>","upvoteCount":0,"datePublished":"2019-05-30T09:32:34.000Z","url":"https://community.spiceworks.com/t/powershell-script-not-running-from-scheduled-task/649971/4","author":{"@type":"Person","name":"gary-m-g","url":"https://community.spiceworks.com/u/gary-m-g"}}]}}