我具有以下代码,这些代码将经过并获取计划的任务信息,并将屏幕上出现的输出放入日志文件。
但是,我注意到的是,除了具有“访问被拒绝”的服务器以外,所有错误都记录在日志中-如何将这些错误也记录在日志文件中。
下面是代码:
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.
这是LOG文件中的输出....否显示未访问权限...?
> 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
最佳答案
连接错误315857中报告了本机命令输出未记录在Start-Transcript输出中但被输出到控制台的这种行为。请参阅变通办法以获取可能的解决方案。
关于powershell - start-Transcript无法捕获所有输出到日志文件。,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13160759/