start-Transcript 未将所有输出捕获到日志文件..? [英] start-Transcript not capturing all output to log file..?
问题描述
我有下面的代码,它通过并获取计划任务信息并将屏幕上发生的输出放入日志文件.
I have the below code that goes through and gets scheduled tasks info and puts the output that occurs on the screen to a log file.
但是,我注意到除了具有访问被拒绝"的服务器之外的所有错误都被记录了 - 我如何也将这些错误记录在日志文件中.
However, what I have noticed is that all errors are logged EXCEPT for servers that have "Access is denied" - how can I log those errors in the log file as well.
代码如下:
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.
这是日志文件中的输出....没有显示拒绝访问...?
Here is the output in the LOG file....no ACCESS IS DENIED Shown...?
> 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
推荐答案
本机命令输出未记录在 Start-Transcript 输出中但输出到控制台的这种行为在连接错误中报告 315857.查看可能的解决方案的变通方法.
This behavior with native command output not being recorded in Start-Transcript output but being output to the console is reported in connect bug 315857. See workarounds for possible solutions.
这篇关于start-Transcript 未将所有输出捕获到日志文件..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!