Live output command ?

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Dave Wyatt Dave Wyatt 1 year, 9 months ago.

  • Author
    Posts
  • #23397
    Profile photo of Graham Beer
    Graham Beer
    Participant

    Hi,

    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 🙂

    Thanks,

  • #23398
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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
    Profile photo of Graham Beer
    Graham Beer
    Participant

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

  • #23400
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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.