简体   繁体   English

Powershell 任务计划程序卡在运行

[英]Powershell Task Scheduler Stuck Running

I was trying to test a simple powershell script with task scheduler, the status showed running but the powershell console never showed up.我试图用任务调度程序测试一个简单的 powershell 脚本,状态显示正在运行,但 powershell 控制台从未出现。

My ps1 script just contains two simple commands:我的 ps1 脚本只包含两个简单的命令:

  • 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程序/脚本:C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
  • Add arguments (optional): -file E:\iQ_Schedule\Untitled1.ps1添加参数(可选):-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).此设置适用于其他计算机(Windows 10),但不适用于这台计算机(Windows Server 2012 R2)。 I am not sure why.我不确定为什么。

Welcome to Session 0 isolation mode.欢迎使用Session 0隔离模式。

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.当您使用“无论用户是否登录都运行”运行任务时,它会在所谓的会话 0 中运行。您可以使用任务管理器进行检查。

在此处输入图像描述 在此处输入图像描述

Tasks running is Session 0 has restrictions on showing the user interface正在运行的任务是会话 0 对显示用户界面有限制

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.当脚本使用 SYSTEM 帐户运行时,脚本将在后台运行。

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.然后应该会弹出 PowerShell 控制台。

It sounds like the Windows Server 2012 R2 could have PSversion 2. The Pause function doesn't exist until PSversion 3.听起来 Windows Server 2012 R2 可能有 PSversion Pause功能直到 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. Run whether user is logged on or not ,仍然会给你提示。 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.我还看到尝试在任务计划程序中运行 PowerShell 脚本的用户无权访问文件夹结构。 Make sure the user that is running the Task Scheduler has access to E:\iQ_Schedule\ .确保运行任务计划程序的用户有权访问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.确保运行任务计划程序的用户对您尝试查找的文件结构具有读取权限。

You can run as SYSTEM user, but then use the executionpolicy bypass argument您可以以 SYSTEM 用户身份运行,但随后使用 executionpolicy bypass 参数

Powershell -ep Bypass 'e:\myPSFile.ps1' -myArg1 'arg1' -myArg2 'arg2' Powershell -ep 绕过 'e:\myPSFile.ps1' -myArg1 'arg1' -myArg2 'arg2'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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