Live output command ?

This topic contains 3 replies, has 2 voices, and was last updated by  Dave Wyatt 3 years, 4 months ago.

  • Author
  • #23397

    Graham Beer


    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 🙂


  • #23398

    Dave Wyatt

    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.

  • #23399

    Graham Beer

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

  • #23400

    Dave Wyatt

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

You must be logged in to reply to this topic.