2014-08-31 55 views
2

我希望调度程序启动我的powershell脚本。这个脚本(重新)写在其启动的第一时间戳:赢7调度程序不启动PowerShell脚本 - 该怎么办?

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

如果这是写我可以肯定的脚本(而不是只PowerShell中)已经开始。

我在调度中定义该任务
- 用户:SYSTEM和
- 最高的特权和其他选项卡中的所有其他的东西。

在操作-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.行中输入我总能启动任务和任务保持运行
但文件Status.log是从未重写过。所以调度程序只启动powershell但不是我的脚本?

如果我尝试(得到了来自谷歌)在PROGRAMM/Skript行输入都喜欢(离开参数数量为空。):

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

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

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

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

由于提前,
Gooly

我说我尝试的结果来运行该脚本。我要么得到另外两个正在运行启动错误(第一次),但他们没有在日志文件中写入时间戳 最初的剧本线:

$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) 

1 TRY(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. 

3 TRY(马特)

使用这些参数
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. 
+0

[following](http://stackoverflow.com/questions/25385325/how-to-run-a-scheduled-task-to-stop-and-start-ssrs-service-with-elevated-permiss/ 25390928#25390928)包含我为大部分脚本运行的内容。关键是通常的执行模式。另外,你不会说你得到了什么错误:“我立即发现启动错误,没有任何事情正在运行。” – Matt 2014-08-31 21:00:37

回答

1

尝试:

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

如果这不起作用,请张贴实际的错误信息,如果您有它。

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

+0

我尝试了你的建议并得到了和以前一样的结果:也没有错误,只是info:powershell是以a.m.选项启动的,但是Status.log文件没有写入。所以我放弃了,并在优秀的旧Autostart文件夹中放置了一个快捷方式。 – gooly 2014-08-31 23:46:18