简体   繁体   中英

How do I get Powershell to execute in scheduled task?

I have created a Powershell script and set it up to run within a .bat file. When I click on the .bat file the Powershell script runs like a champ. I then set up the .bat file to be run as a scheduled task. Again it works like a champ when I right click on it and launch it interactively. Problem is it fails when the task scheduled to run unattended in the evening.

Not sure if this matters but I am using Powershell v.1 on Windows 2003 Server 64.

Thanks in advance for your help.

========================================== The status on the scheduled task is "Could not start". Perhaps fails was the wrong choice of words because the task probably doesn't even start running.

The task is set up to run as my user and I am set up as a local administrator on the box.

Check if scheduled task's security setting Scheduled task might be running under a credential that does not have access to the batch file.

When you are adding a new task, you are asked to enter a credential

替代文字

And you can check for already created task's credential 替代文字

[UPDATE]

The status on the scheduled task is "Could not start". Perhaps fails was the wrong choice of words because the task probably doesn't even start running.

Make sure that Task Scheduler service is running
替代文字

Is the task set to run with your useraccount or as System? Check the access rights on cmd.exe and powershell.exe.

Also if you go to the sheduled tasks you can do a 'view log' in the advanced menu to check for error messages.

Just a guess, but could it be something to do with the account/security context from which the script is running? If it's running on the System account, then that could certainly be a problem. (I suspect it's just running on your user account however.) Check that all your path variables are set correctly when the script runs, for a start. Otherwise, could you perhaps provide any more information on how exactly it fails (ie any error messages)?

Maybe the current directory is not set as you expect when running from the task manager. Try running your bat file from the command line, while you are not in the same directory as the file (and your .ps1 script) are.

Otherwise: check permissions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM