windows 2008 年使用 powershell 调度任务
scheduling task in windows 2008 with powershell
我想用 powershell 在 windows 2008 r2 中安排任务。我用了
$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 : ERROR: The task XML contains a value which is incorrectly formatted or out of range." 相同的脚本在 windows 7.
上工作正常
似乎存在密码问题,已在下面 post 中解决:
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.
我想用 powershell 在 windows 2008 r2 中安排任务。我用了
$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 : ERROR: The task XML contains a value which is incorrectly formatted or out of range." 相同的脚本在 windows 7.
上工作正常似乎存在密码问题,已在下面 post 中解决:
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.