Attention Don Jones

What is your opinion on this now?

Write-Host is the only way to return output to the console in GUI’s. Well I shouldn’t say only, but quickest.


“Console in GUIs?” I’m not sure I know what you mean.

In writing powershell based forms you have to constantly validate selections, mouseclicks, buttons etc. write-output, write-verbose, write-debug will not output your results to a console.

The only viable options are to write-host, output to file, or write to a text control. Write-host is the most efficient way to return results to the console.

Never say never;-)

I still say never :). Write-Verbose, for example, works fine for me in that exact scenario, provided I’ve enabled the pipeline. But I tend to build my own logging function so I can direct output to a file, the console, or whatever, using a flag. That gives me a log for unattended execution as well as live debugging.

seems pretty arduous a task to do all that when you just want to make sure for example the right value is returned when making a selection from a combobox, no?

If you’re unhappy with the way Write-Verbose works you can just re-write it. I’ve built myself quite a module over the last few months that has all kinds of funky functionality. For example, this is my Write-Verbose function:

function Write-Verbose([parameter(mandatory)][string]$Message) {
    if($VerbosePreference -eq 'Continue') {
        Microsoft.PowerShell.Utility\Write-Verbose -Message $Message
        ('{0} VERBOSE: {1}' -f $stopWatch.Elapsed.ToString(), $Message) | Out-File -Append -FilePath $logFilePath -Encoding utf8

This captures verbose output and dumps it in a file, as well as writing the message back to the original Write-Verbose command.

Granted with PS5 it should be possible to handle this is an easier way, what with the new output streams and whatnot, but we can’t all be putting PS5 into production just yet, even though the guys say WMF5 can handle it.

FWIW, I’m a big fan of the new Write-Information. I’m less a fan of having Write-Host half hooked up to that. It makes -Host semantically vague. I’d STILL avoid it, and use -Information if that’s what I wanted. It’s more specific, and there’s no risk of a hard to see version incompatibility.

What version of PS can i find Write-Information or is this a 3rd party add-on?


oh ok thanks. I have 5.0.9883.0 running on a test machine but i dont see that cmdlet. Coming in a updated version or do i have to enable it?

I’m not sure if that’s in a public build or not yet.