Forum Discussion
Task Scheduler to run PowerShell
Hello
I have a windows PowerShell Script that I made to move a folder to anther folder on the same drive. (move-item 'E:\System State Folder' 'E:\Backup Folder') Action : Start a Program, Program/script: PowerShell, Add arguments: -ExecutionPolicy Bypass, Start in: C:\Users\Administrator\Desktop\Test.ps1
PowerShell opens but the folders do not move.
- MaluksIron Contributor
you forgot "-file" argument where you set path to your PS script. Please read more here https://blogs.technet.microsoft.com/heyscriptingguy/2012/08/11/weekend-scripter-use-the-windows-task-scheduler-to-run-a-windows-powershell-script/
And you might also need to run the script as administrator. In any case, add some logging/debugging capabilities in the script in order to troubleshoot it properly.
- Paul McLaughlinCopper ContributorI have in the task scheduler run as administrator but still nothing, I can run the script by using the open with PowerShell and it will work. Just cant get the darn to work as a task.
- MaluksIron Contributor
Paul, as I mentioned you are mising "-file" parameter, as from the script I see that you have mixed it with "-Start in" as this should be the directory where the script should run and not the path to your script as this parameter is optional
- Anders RødlandCopper Contributor
I wrote a blog post in March on how to use task scheduler to run PowerShell scripts with arguments: https://www.andersrodland.com/powershell-script-with-arguments-as-a-scheduled-task/