Welcome to MSDN Blogs Sign in | Join | Help

Use of Preference Variables to control behavior of streams

PSMDTAG:FAQ: Why don't I see output when I use Write-Verbose and Write-Debug?
PSMDTAG:SHELL: Use of Preference Variables to control behavior of streams.

In Windows PowerShell, the WRITE-XXX cmdlets merely sends things to a Named stream.  You then have user-defined preferences for what to do when things appear on that stream.  Alex Angelopoulos provided the following function TEST-WRITER to highlight the issue:

function Test-Writer
    {
        'Will test Write -Host, -Output, -Verbose, -Warning, -Error.'
        Write-Host 'Write-Host'
        Write-Output 'Write-Output'
        Write-Verbose 'Write-Verbose'
        Write-Warning 'Write-Warning'
        Write-Error 'Write-Error'
        'Done with test.'
    }


PS> test-writer
Will test Write -Host, -Output, -Verbose, -Warning, -Error.
Write-Host
Write-Output
WARNING: Write-Warning
Test-Writer : Write-Error
At line:1 char:11
+ test-writer <<<<
Done with test.

Notice the lack of "Write-Verbose" and "Write-Debug"


PS> dir variable:*preference

Name                           Value
----                           -----
DebugPreference                SilentlyContinue
VerbosePreference              SilentlyContinue
ProgressPreference             Continue
ErrorActionPreference          Continue
WhatIfPreference               0
WarningPreference              Continue
ConfirmPreference              High


PS> $DebugPreference=$VerbosePreference="Continue"
PS> test-writer
Will test Write -Host, -Output, -Verbose, -Warning, -Error.
Write-Host
Write-Output
VERBOSE: Write-Verbose
WARNING: Write-Warning
Test-Writer : Write-Error
At line:1 char:11
+ test-writer <<<<
Done with test.
PS>

Enjoy!


Jeffrey Snover [MSFT]
Windows PowerShell Architect
Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

Published Tuesday, July 04, 2006 5:13 AM by PowerShellTeam
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker