相关疑难解决方法(0)

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

我有以下代码通过并获取计划任务信息并将屏幕上发生的输出放到日志文件中.

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

以下是代码:

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
Run Code Online (Sandbox Code Playgroud)

这是屏幕上的输出:

> Running Against Server SV064909 
> SV064909 is Down 
> …
Run Code Online (Sandbox Code Playgroud)

powershell powershell-2.0

19
推荐指数
2
解决办法
2万
查看次数

标签 统计

powershell ×1

powershell-2.0 ×1