Live output command ?


I’m trying to write a script that will update a log file with each step of an OSD task sequence in SCCM. Is there a way to capture the output as it happens to a log file ?

This is what i have so far:

Set Environment and log details

$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
#$logPath = “C:\temp”
$logPath = $tsenv.Value(“_SMSTSLogPath”)
$logFile = “$logPath$($env:COMPUTERNAME).log”

Start logging

Start-Transcript $logFile

$tsenv.Value('SMSTSCurrentActionName’) | foreach { Write-output "$ = $($tsenv.Value($_))" }

Stop logging

Its a good learning exercise for me as well :slight_smile:


You can use Get-Content with the -Wait switch (in a separate window, of course), though I’ve occasionally run into situations where that didn’t show the output until the other process closed the file, for some reason. If you find you’re in that situation, you can also look for “tail.exe”; there are many windows ports of that command, which does the same thing using native API calls that seem to be more reliable.

Could i use -stream in get-content to do the same thing ?

The -Stream parameter is for reading NTFS Alternate Data Streams. Not terribly helpful here, most likely. :slight_smile: