start-Transcript not capturing all output to log file..?

♀尐吖头ヾ 提交于 2019-11-28 11:55:29

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.

The simplest workaround is to pipe the results of the native command to Out-Host

schtasks.exe /query /S $name /fo CSV /v >$scheduledpath\$name.csv | Out-Host

None of the above worked for me. I found a link from 2009 with discussions of the issue. But a microsoft blog from 2010 solved the issue for me.

In short, pipe the native command output to Out-Default.

  schtasks.exe /query /S $name /fo CSV /v | Out-Default

{I didn't really try that line myself, but you get the idea.}

Ahh, the correct answer should be:

$Command = "schtasks.exe /query /S $name /fo CSV /v 2>&1 >$scheduledpath\$name.csv"

I.e. pipe stderror (pipe 2) to stdout (pipe 1), so that both shows in the stdout.

Get service tag

    $servicetag = Get-WmiObject win32_bios | Select-Object -ExpandProperty SerialNumber 
    Write-output $servicetag

I used Write-output in one line at the top of my script, after that one they were all Write-Host. But every "Write" output is now showing up in my script.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!