January 4th, 2010

Workaround for Start-Transcript on native processes

PowerShell Team
PowerShell Team

Introduction

Recently, we came across an interesting bug that had been around for awhile (http://connect.microsoft.com/PowerShell/feedback/ViewFeedback.aspx?FeedbackID=315875). If you do the following:

Start-Transcript
ipconfig
Stop-Transcript

If you look at the transcript, you’ll see that the output of ipconfig was not captured.

Why is this happening?

PowerShell recognizes that ipconfig is a native console application. Since many of these applications do direct writes to the console buffer (i.e. more.com, edit.com etc.), we don’t direct the output handles. Because of that, we can’t capture their output directly. This renders the transcription framework ineffective because the Out-Default cmdlet is unable to capture anything from ipconfig.

How can we work around it?

The workaround is actually quite simple. All you have to do is to pipe the output from ipconfig.exe to Out-Default.

Start-Transcript
ipconfig | Out-Default
Stop-Transcript

Tianjie (James) Wei [MSFT]
Software Design Engineer
Windows PowerShell Team

Category
PowerShell

Author

PowerShell Team
PowerShell Team

PowerShell is a task-based command-line shell and scripting language built on .NET. PowerShell helps system administrators and power-users rapidly automate tasks that manage operating systems (Linux, macOS, and Windows) and processes.

0 comments

Discussion are closed.