PowerShell tee-object limitations

sdsdI currently have a script that is executed as follows:
.\script.ps1 “param1” “param2” 2>&1 | tee -filePath buildlog.txt

I would like it to not require the -tee parameter and instead have the logging to both the console and file encapsulated within the script.
.\script.ps1 “param1” “param2”

Here’s a sample script highlighting the limitation. Executing .\powershelltest.ps1 logs to the console, but not to a file.

# powershelltest.ps1
param([string]$paramOne, [string]$paramTwo)

function DoWork()
 Write-Host '3'

function WriteLogFile()
 # The following would not be captured by Start-Transcript & Stop-Transcript
 # program.exe ....
 Write-Host '4'

function CollectorFunction()
    Write-Host '2'
    Write-Host '5'

Write-Host '1'
CollectorFunction 2>&1 | tee -filePath c:\log.foo

There does not seem to be a way to do this with the Tee-Object cmdlet. Start-Transcript and Stop-Transcript do not log from executables which my script is using. I’m currently out of ideas.

This entry was posted in .Net and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s