-1

我想在Windows 2008 R2中使用PowerShell計劃任務。我用使用PowerShell的Windows 2008中的計劃任務

$username = "BUILTIN\Users" 
    $TaskName = 'kakaka' 
    $t=1 
    $TaskRun = "$PSHome\powershell.exe Start-Process -FilePath 'C:\v.exe' -ArgumentList '/a' -Verb runas -WindowStyle Normal" 
    $start = (Get-Date).AddMinutes($t).ToString("HH:mm") 
    schtasks /create /ru $username /tn $Taskname /tr $TaskRun /sc once /st $start /f 

上使用上述腳本我得到一個錯誤「SchTasks.exe會:錯誤:任務XML包含格式不正確或超出範圍的值。」同樣的腳本運行良好在Windows 7

+1

部分是'$ Taskname'當它在通話中擴展時不會被引用。嘗試在變量周圍加引號:'/ tn「$ Taskname」' – Matt

+0

@Matt no man thats not problem。檢查。 –

+0

爲什麼在計劃任務中通過PowerShell運行可執行文件?運行具有最高權限的可執行文件('/ tr'「C:\ v.exe/a」'/ rl highest')還不夠嗎? –

回答

0

似乎有密碼的問題,這是後下解決了:

你可能有這個問題的https://social.technet.microsoft.com/forums/windowsserver/en-US/fe7345ea-b037-469b-b425-17d5fee28e91/windows-server-backup-wont-schedule

SYMPTOMS 

When you try to change the run as user for a scheduled task in Server 2008, The task is currently configured to runas SYSTEM. Using the following command line he receives the error. 

c:\>SCHTASKS /CHANGE /TN TestTask /RU TestUser 

SCHTASKS prompts the user for a password for the runas user account. After entering the password it displays the following error. 


"ERROR: The task XML contains a value which is incorrectly formatted or out of range. (52,4):Task:" 


The task's runas credentials have not changed. 


RESOLUTION 

To avoid this error you must add the /RP option with an "*". The new command line will look like this: 

c:\>SCHTASKS /CHANGE /TN TestTask /RU TestUser /RP * 

SCHTASKS prompts the user for a password for the runas user account. After entering the password the task is updated without error. 
+0

是...現在可以使用選項「/ rp *」來安排任務,但它沒有運行。不知道爲什麼。 –

+0

這已經成功繞過了錯誤。但沒有運行任務。你知道爲什麼和上面的更正爲你工作嗎??? –

相關問題