Task Scheduler to run PowerShell

%3CLINGO-SUB%20id%3D%22lingo-sub-86425%22%20slang%3D%22en-US%22%3ETask%20Scheduler%20to%20run%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-86425%22%20slang%3D%22en-US%22%3E%3CP%3EHello%3C%2FP%3E%3CP%3EI%20have%20a%20windows%20PowerShell%20Script%20that%20I%20made%20to%20move%20a%20folder%20to%20anther%20folder%20on%20the%20same%20drive.%20(move-item%20'E%3A%5CSystem%20State%20Folder'%20'E%3A%5CBackup%20Folder')%20Action%20%3A%20Start%20a%20Program%2C%20Program%2Fscript%3A%20PowerShell%2C%20Add%20arguments%3A%20-ExecutionPolicy%20Bypass%2C%20Start%20in%3A%26nbsp%3BC%3A%5CUsers%5CAdministrator%5CDesktop%5CTest.ps1%3C%2FP%3E%3CP%3EPowerShell%20opens%20but%20the%20folders%20do%20not%20move.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-86425%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-108592%22%20slang%3D%22en-US%22%3ERe%3A%20Task%20Scheduler%20to%20run%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-108592%22%20slang%3D%22en-US%22%3E%3CP%3EI%20wrote%20a%20blog%20post%20in%20March%20on%20how%20to%20use%20task%20scheduler%20to%20run%20PowerShell%20scripts%20with%20arguments%3A%20%3CA%20href%3D%22https%3A%2F%2Fwww.andersrodland.com%2Fpowershell-script-with-arguments-as-a-scheduled-task%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.andersrodland.com%2Fpowershell-script-with-arguments-as-a-scheduled-task%2F%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-86712%22%20slang%3D%22en-US%22%3ERe%3A%20Task%20Scheduler%20to%20run%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-86712%22%20slang%3D%22en-US%22%3E%3CP%3EIt%20works%20great%20thanks%20for%20the%20quick%20response%20.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-86526%22%20slang%3D%22en-US%22%3ERe%3A%20Task%20Scheduler%20to%20run%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-86526%22%20slang%3D%22en-US%22%3E%3CP%3ESorry%20I%20didn't%20see%20your%20post%20earlier%20I%20will%20give%20it%20a%20try%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-86523%22%20slang%3D%22en-US%22%3ERe%3A%20Task%20Scheduler%20to%20run%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-86523%22%20slang%3D%22en-US%22%3E%3CP%3EPaul%2C%20as%20I%20mentioned%20you%20are%20mising%20%22-file%22%20parameter%2C%20as%20from%20the%20script%20I%20see%20that%20you%20have%20mixed%20it%20with%20%22-Start%20in%22%20as%20this%20should%20be%20the%20directory%20where%20the%20script%20should%20run%26nbsp%3Band%20not%20the%20path%20to%20your%20script%20as%20this%20parameter%20is%20optional%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-86517%22%20slang%3D%22en-US%22%3ERe%3A%20Task%20Scheduler%20to%20run%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-86517%22%20slang%3D%22en-US%22%3EI%20have%20in%20the%20task%20scheduler%20run%20as%20administrator%20but%20still%20nothing%2C%20I%20can%20run%20the%20script%20by%20using%20the%20open%20with%20PowerShell%20and%20it%20will%20work.%20Just%20cant%20get%20the%20darn%20to%20work%20as%20a%20task.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-86512%22%20slang%3D%22en-US%22%3ERe%3A%20Task%20Scheduler%20to%20run%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-86512%22%20slang%3D%22en-US%22%3E%3CP%3EAnd%20you%20might%20also%20need%20to%20run%20the%20script%20as%20administrator.%20In%20any%20case%2C%20add%20some%20logging%2Fdebugging%20capabilities%20in%20the%20script%20in%20order%20to%20troubleshoot%20it%20properly.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-86464%22%20slang%3D%22en-US%22%3ERe%3A%20Task%20Scheduler%20to%20run%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-86464%22%20slang%3D%22en-US%22%3E%3CP%3Eyou%20forgot%20%22-file%22%20argument%20where%20you%20set%20path%20to%20your%20PS%20script.%20Please%20read%20more%20here%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fblogs.technet.microsoft.com%2Fheyscriptingguy%2F2012%2F08%2F11%2Fweekend-scripter-use-the-windows-task-scheduler-to-run-a-windows-powershell-script%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fblogs.technet.microsoft.com%2Fheyscriptingguy%2F2012%2F08%2F11%2Fweekend-scripter-use-the-windows-task-scheduler-to-run-a-windows-powershell-script%2F%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

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.

7 Replies

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...

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.

I 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.

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

Sorry I didn't see your post earlier I will give it a try

It works great thanks for the quick response . 

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/