Live output command ?

Welcome Forums General PowerShell Q&A Live output command ?

This topic contains 3 replies, has 2 voices, and was last updated by

 
Member
3 years, 7 months ago.

  • Author
    Posts
  • #23397

    Participant
    Points: 0
    Rank: Member

    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

    Member
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

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

  • #23400

    Member
    Points: 0
    Rank: Member

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

The topic ‘Live output command ?’ is closed to new replies.