gpt4 book ai didi

powershell - start-Transcript 未将所有输出捕获到日志文件..?

转载 作者:行者123 更新时间:2023-12-02 22:36:40 26 4
gpt4 key购买 nike

我有下面的代码,它会执行并获取计划任务信息,并将屏幕上发生的输出放入日志文件中。

但是,我注意到,除了“访问被拒绝”的服务器之外,所有错误都会被记录 - 我如何才能在日志文件中记录这些错误。

下面是代码:

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

最佳答案

连接错误 315857 中报告了 native 命令输出未记录在 Start-Transcript 输出中而是输出到控制台的行为。 。查看可能的解决方案的变通方法。

关于powershell - start-Transcript 未将所有输出捕获到日志文件..?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13160759/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com