【发布时间】:2017-11-19 12:32:01
【问题描述】:
function ServiceRestart
{
Param
(
$ErrorLog,
$Services,
$MaxSize
)
$Time = Get-Date -Format 'yyyy:MM:dd HH:mm:ss'
$Result = (Get-Item $ErrorLog).length
if($Result -gt $MaxSize)
{
Clear-Content $ErrorLog
}
Try
{
Foreach($Service in $Services)
{
Restart-Service -DisplayName $Service -ErrorAction Stop
}
} Catch
{
"ERROR: $Service could not be restarted $Time" | Add-Content $ErrorLog
}
}
ServiceRestart -ErrorLog -Services -MaxSize
我需要从任务计划程序中传入以下参数
- 错误日志
- 服务
- 最大尺寸
我目前有这样的任务计划程序设置
程序/脚本:C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
添加参数(可选):
-Command "& \ServerName\C$\Users*****\Documents\Scripts\Scheduled-ServiceRestart.ps1
-ErrorLog 'ServerName\C$\Users *****\Documents\log\ScriptErrors.txt'
-Services 'foo1' , 'foo2'
-MaxSize '5MB'"
当我运行计划任务时,没有任何反应,可能出了什么问题。
【问题讨论】:
标签: powershell scheduled-tasks