Running a powershell script as a daily task on a WIndows 2012r2 server

I have a new script that goes out and deletes .Tar files that are over 7 days old. It runs perfectly when I run it from the command line with ./ but I cannot seem to get it to run as a scheduled task.
I opened my Task Scheduler and configured a Trigger to run every day at 8:30pm and an Action to "Start a program" the Program/Script is "powershell" and my Argument is
 "-file "C:\script\DeleteOldBackups.ps1"

I go to manually RUN the script from the Task Scheduler and nothing happens, but if I run it from the PS command prompt, files delete as expected. Any advice? Does my argument have an error??
LVL 1
Thor2923Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wayne88Commented:
So your script is:

powershell -file "C:\script\DeleteOldBackups.ps1"

Can you try using the whole command directly in the program/script field as shown in this example: http://blogs.technet.com/b/heyscriptingguy/archive/2012/08/11/weekend-scripter-use-the-windows-task-scheduler-to-run-a-windows-powershell-script.aspx
zalazarCommented:
Can you please try it to run as
powershell.exe -ExecutionPolicy Unrestricted -File "C:\script\DeleteOldBackups.ps1"

Open in new window

Also select "Run with highest privileges" on the General tab.
So program/script should be: powershell.exe
and argument:
-ExecutionPolicy Unrestricted -File "C:\script\DeleteOldBackups.ps1"

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Brian ScholerCommented:
I can't tell for sure from your question but it sounds like you might be deleting files on another computer (other than the one where your script is running), perhaps through a UNC path?

If so, then I would check the user account that is set to run the scheduled task. If the task is running as SYSTEM and your computer is joined to a domain, then your script will be accessing the share as the domain computer account (COMPUTERNAME$), which probably doesn't have access to the UNC path.

You can either run the scheduled task as a user who has permissions on the share, or you can give "Domain Computers" or "Authenticated Users" or the specific computer account write access to the share.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2012

From novice to tech pro — start learning today.