Powershell Task Scheduler Stuck Running

a 夏天 提交于 2019-12-13 21:46:12

问题


I was trying to test a simple powershell script with task scheduler, the status showed running but the powershell console never showed up.

My ps1 script just contains two simple commands:

  • dir
  • pause

Here is my setup:

General

  • Run whether user is logged on or not (check)
  • Run with highest privileges (check)

Actions

  • Action: Start a program
  • Program/Script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
  • Add arguments (optional): -file E:\iQ_Schedule\Untitled1.ps1

This setup works on other computer (Windows 10) but just won't on this one (Windows Server 2012 R2). I am not sure why.


回答1:


Welcome to Session 0 isolation mode.

When you run your task with "Run whether user logged in or not", it runs in so called session 0. You can check this with your task manager.

Tasks running is Session 0 has restrictions on showing the user interface




回答2:


This could be due to the user account which is running the script. When the script is running with the SYSTEM account, the script will run in the background.

Try to change the option 'When running the task, use the following user account' to the account you are currently logged on with. Then the PowerShell console should pop up.




回答3:


It sounds like the Windows Server 2012 R2 could have PSversion 2. The Pause function doesn't exist until PSversion 3.

Could you give the value of this command to us?

$PSVersionTable.PSVersion

Run whether user is logged on or not, will still give you the prompt. If the Hidden option is checked, you will not see the prompt.

I have also seen that the user that is trying to run the PowerShell script inside Task Scheduler doesn't have access to the folder strucutre. Make sure the user that is running the Task Scheduler has access to E:\iQ_Schedule\.

Make sure the user that is running the task scheduler has read access to the file structure you are trying to look up.



来源:https://stackoverflow.com/questions/45110750/powershell-task-scheduler-stuck-running

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!