Scheduled Task to run PowerShell script

I’m trying to create a task in Task Scheduler that will run a PowerShell script at 12:00 am every day and it’s not working, here are my settings: (see attach).
I’m also including a copy of the script file in notepad. Can anyone help? Thanks.
SettingsScript.txt
narce100Asked:
Who is Participating?
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:
Does it work when you manually run the task?

Windows 7, Server 2008, etc. is very finicky with running scheduled task because we find that you cannot be logged off or the task won't run for example.  Some others claimed making the task to run as administrator and wake computer up automatically, etc. worked for them.

First and foremost, set the task to run as a user with administrator privileges.
0
Will SzymkowskiSenior Solution ArchitectCommented:
You have the incorrect syntax in the Task scheduler to run this script. You cannot call a .PS1 script separately. You first need to call powershell. So it should look like below...

Details should look like below...
powershell.exe -file "c:\filepath\scriptname.ps1"

Once you have it set like above it should run successfully.

Will.
0
narce100Author Commented:
Wayne88: Yes I run the script manually every day for quite some time but now I need to run it late at night.

Will: I'll try that syntax and see if it works.
0
ON-DEMAND: 10 Easy Ways to Lose a Password

Learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees in this on-demand webinar. We cover the importance of multi-factor authentication and how these solutions can better protect your business!

narce100Author Commented:
I wrote a shorter and easier version of the report.ps1 file, it ran well manually but when I set up the trigger to run a few minutes after my current time. It does not seem to work, but the log shows that it did. Attached is a print screen with the settings and a notepad copy of the file.
New-seetings.PNG
More-settings.PNG
Script.txt
0
Will SzymkowskiSenior Solution ArchitectCommented:
Another thing you can try is just call the powershell script from a batch file.
http://stackoverflow.com/questions/19335004/how-to-run-a-powershell-script-from-a-batch-file

Will.
0
Joshua GrantomSenior Systems AdministratorCommented:
Will is correct on his post about using

powershell.exe -file "c:\filepath\scriptname.ps1"

Here is what it should look like.

Capture.PNG
0
narce100Author Commented:
The task ran and was completed according to Task Scheduler history log; but I don't see the script run or the files that are supposed to generate are not on the designated folder see attach for settings and script file
History-log.PNG
Action-Settings.PNG
PowerShell-Script.txt
0
Joshua GrantomSenior Systems AdministratorCommented:
What account are you running the task under? If the S Drive is not a local drive and it's actually a network drive then you will need to mount S: within the script as well
0
narce100Author Commented:
I already have a map on my desktop to the S: drive and when creating the Task I sign in as myself (Domain Administrator) and the logon window disappears after that.
It runs fine when I do it manually; do I have to write the entire path instead of the mapping on the script?
0
Joshua GrantomSenior Systems AdministratorCommented:
Yes I would. Including the entire network path will reduce the points of failure. Did you put in your credentials so that the task will run using your active directory account?
0
narce100Author Commented:
Yes, actually a window comes up every time you modify something on the task scheduler and prompts you to type username/password under the task will run on.
I will write the entire path and keep you posted on the results
0
narce100Author Commented:
I typed the entire path and the task since to run with no problem is the PowerShell script that does not run, I don't see it come up or anything.
new-task-scheduler-screeshot.PNG
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
The S: drive cannot be used in the task, so using the UNC path is correct.
But since the file is not generated, and the task runs for 2 minutes, something is executed, but either there is no result or the file cannot get created.
Put a sleep 300 at the end of the PS script, set the task to run only if you are logged in, and then kickstart the task. You should see the window now for about 7 minutes. In particular you should see if errors are encountered.
0

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
narce100Author Commented:
It worked, I have some fine tune to do in the script but is fine.

Thank You.
0
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
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.