【问题标题】:win 7 scheduler does not start a powershell script - what to do?win 7 调度程序不启动 powershell 脚本 - 怎么办?
【发布时间】:2014-08-31 16:03:21
【问题描述】:

我希望调度程序启动我的 powershell 脚本。该脚本(重新)首先写入其开始的时间戳:

   $StatusFile = $Env:USERPROFILE+"\Desktop\Status.log"
   set-content $StatusFile "Start $($((get-date).ToString('ddd. yyyy.MM.dd HH:mm:ss')))"

如果这是写的,我可以确定脚本(不仅是 powershell)已经启动。

我在调度器中为这个任务定义了
- 用户:SYSTEM 和
- 最高权限和其他选项卡的所有其他内容。

在 Actions-Tab 我定义:
1) 操作 =“程序启动”
2) Programm/Skript = powershell.exe (或 C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe)
3) 参数(可选):

a)  C:\Users\calli\Desktop\TimeSync_v2.ps1
b) -file "C:\Users\calli\Desktop\TimeSync_v2.ps1"
c) -command "C:\Users\calli\Desktop\TimeSync_v2.ps1"
d) -file C:\Users\calli\Desktop\TimeSync_v2.ps1
   ....

无论我在 Arg.-Line 中输入什么内容,我始终可以启动任务并且任务继续运行
但从未重写过 Status.log 文件。所以调度器只启动powershell而不启动我的脚本??

如果我尝试(从 google 获取)在 Programm/Skript-line 中输入所有内容(将 Args 留空),例如:

 powershell.exe -file "C:\Users\calli\Desktop\TimeSync_v2.ps1"

(即使这里有各种版本)我立即得到一个启动错误并且没有运行。

我什至尝试设置:s.th.就像在启动一个新实例时杀死一个正在运行的实例(如果我没记错的话)。

我该怎么办?我的错在哪里?

提前致谢,
古力

我添加了我尝试运行脚本的结果。我要么得到启动错误(第二次尝试),另外两个正在运行,但它们都没有在日志文件中写入时间戳 初始脚本行:

  $StatusFile = $Env:USERPROFILE+"\Desktop\TimeSyncStatus.log"
  set-content $StatusFile "Starte TimeSync $($( (get-date).ToString('ddd. yyyy.MM.dd HH:mm:ss') ))"
  do { chkSync } while ( $true )

第一次尝试(briantist)

  Action: powershell -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -File 'C:\Users\calli\Desktop\TimeSync_v2.ps1'"
  Add Args: -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -File C:\Users\calli\Desktop\TimeSync_v2.ps1"
  Start in: (empty)
  Task Scheduler started "{fad9623d-7527-48c7-a95c-4adac7e0dba2}" instance of the "\start TimSync" task for user "WORKGROUP\MYMSI$".
  Task Scheduler launched action "powershell" in instance "{fad9623d-7527-48c7-a95c-4adac7e0dba2}" of task "\start TimSync".
  Task Scheduler launch task "\start TimSync" , instance "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.EXE"  with process ID 5824.

第二次尝试(启动错误)

  Action: powershell "-NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -File 'C:\Users\calli\Desktop\TimeSync_v2.ps1'"
  Add Args:
  Start in:
  Task Scheduler launched action "powershell "-NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -File 'C:\Users\calli\Desktop\TimeSync_v2.ps1'"" in instance "{653f5e6a-e992-44d0-8189-fda1d44a114f}" of task "\start TimSync".
  Task Scheduler failed to launch action "powershell -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -File 'C:\Users\calli\Desktop\TimeSync_v2.ps1'" in instance "{653f5e6a-e992-44d0-8189-fda1d44a114f}" of task "\start       TimSync". Additional Data: Error Value: 2147942523.
  Task Scheduler failed to start instance "{653f5e6a-e992-44d0-8189-fda1d44a114f}" of "\start TimSync"  task for user "WORKGROUP\MYMSI$" . Additional Data: Error Value: 2147942523.

第三次尝试(马特)

  Action: %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
  Add arguments: -ExecutionPolicy Unrestricted -NoProfile -File C:\Users\calli\Desktop\TimeSync_v2.ps1
  Start in: Start in (optional): %SystemRoot%\system32\WindowsPowerShell\v1.0
  Task Scheduler started "{3c00ad49-e8a0-48a2-9578-90b512db0932}" instance of the "\start TimSync" task for user "WORKGROUP\MYMSI$".
  Task Scheduler launched action "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe" in instance "{3c00ad49-e8a0-48a2-9578-90b512db0932}" of task "\start TimSync".
  Task Scheduler launch task "\start TimSync" , instance "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe"  with process ID 8980.

【问题讨论】:

  • following 包含我为大多数脚本运行的内容。关键通常是执行模式。另外,你没有说你得到了什么错误:“我立即得到一个启动错误,没有任何东西在运行。”

标签: powershell scheduled-tasks


【解决方案1】:

尝试使用这些参数:

-NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -File "C:\path\to\your\file.ps1"

如果这不起作用,请发布实际的错误消息(如果有)。

或者使用psexecSYSTEM 运行命令提示符,它们运行您从任务中运行的相同命令,这样您就可以看到输出。

【讨论】:

  • 我尝试了您的建议并得到与以前相同的结果:也没有错误,只是信息:powershell 是使用 a.m. 选项启动的,但未写入 Status.log 文件。所以我放弃了,在旧的 Autostart 文件夹中放置了一个快捷方式。
猜你喜欢
  • 2016-07-15
  • 1970-01-01
  • 2018-06-10
  • 2012-02-06
  • 2012-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-14
相关资源
最近更新 更多