我希望調度程序啓動我的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.
[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