Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3352128
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:59:32+00:00 2026-05-18T01:59:32+00:00

I have a PowerShell script that outputs to stdout and stderr. I’d like to

  • 0

I have a PowerShell script that outputs to stdout and stderr. I’d like to tee those to a couple log files at the same time.

What’s the best way to do this?

A couple things I’ve considered:

  • Wrap write-error and write-output with a function that does the tee.
    • I don’t like this much because (a) I lose my easy ability to just put a value on a line and have it automatically output and (b) I’d have to wrap every place that I’m calling something, including native exe’s, that may have output and wrap those as well.
  • Wrap in an outer script that does the tee.
    • This is a little better but now I have the issue of needing to duplicate the param() block from the inner script in the outer script. I could move the param() block entirely but I also want to call the inner script sometimes for testing purposes (i.e. not get the tee). I suppose I could make that an optional behavior in the outer script..

I remember back when I used to write some perl there was a convenient way to redirect all stdout/err output globally, via a hook. Is something like this possible with PowerShell?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:59:33+00:00Added an answer on May 18, 2026 at 1:59 am

    Whoops. I should have spent just a couple more minutes with the Googles.

    Start-Transcript does this!

    http://technet.microsoft.com/en-us/library/dd347721.aspx

    ..though it does not capture output of exe’s, only PowerShell. Here’s a good workaround:

    https://web.archive.org/web/20111106093956/blog.magenic.com/blogs/daniels/archive/2008/07/14/Output-Issue-with-Transcript-in-Powershell.aspx

    Another update: I discovered that Start-Transcript uses the host window buffer width, which is way too narrow when running a scheduled task on the system account or whatever. Here’s how to fix that. Add something like this to the top of the script:

    try
    {
        $host.ui.rawui.buffersize = `
            new-object system.management.automation.host.size `
                200, $host.ui.rawui.buffersize.height
    }
    catch {}
    

    Change the 200 to whatever width you want for the transcript.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.