我有下面的代码,通过去,并得到预定的任务信息,并把该屏幕日志文件上发生的输出。
不过,我已经注意到的是,所有的错误记录,除了有“访问被拒绝”服务器 - 我怎么能在日志文件中记录这些错误也是如此。
下面是代码:
Start-Transcript -path $scheduledpath\logging.txt -append
foreach ($name in $names)
{
Write-Host "Running Against Server $name" -ForegroundColor Magenta
if ( Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue )
{
#$Command = "schtasks.exe /query /S $name /fo CSV /v >c:\tools\Scheduled\$name.csv"
$Command = "schtasks.exe /query /S $name /fo CSV /v >$scheduledpath\$name.csv"
Invoke-Expression $Command
Clear-Variable Command -ErrorAction SilentlyContinue
}
else{
Write-Host "$name is Down" -ForegroundColor Red
}
}
Stop-Transcript
这里是屏幕上的输出:
> Running Against Server SV064909
> SV064909 is Down
> Running Against Server SV081372
> SV081372 is Down
> Running Against Server YBEF008690_vorher_SV064930
> YBEF008690_vorher_SV064930 is Down
> Running Against Server Alt_SV064921
> Alt_SV064921 is Down
> Running Against Server SV073632
> ERROR: Access is denied.
> Running Against Server SV073633
> ERROR: Access is denied.
下面是在日志文件输出....没有访问被拒绝出...?
> Running Against Server SV064909
> SV064909 is Down
> Running Against Server SV081372
> SV081372 is Down
> Running Against Server YBEF008690_vorher_SV064930
> YBEF008690_vorher_SV064930 is Down
> Running Against Server Alt_SV064921
> Alt_SV064921 is Down
> Running Against Server SV073632
> Running Against Server SV073633