Attention Don Jones

This topic contains 10 replies, has 4 voices, and was last updated by Profile photo of Don Jones Don Jones 1 year, 8 months ago.

  • Author
    Posts
  • #25000
    Profile photo of Dan Potter
    Dan Potter
    Participant

    What is your opinion on this now?

    http://m.windowsitpro.com/blog/what-do-not-do-powershell-part-1

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

    Dan

  • #25001
    Profile photo of Don Jones
    Don Jones
    Keymaster

    "Console in GUIs?" I'm not sure I know what you mean.

  • #25003
    Profile photo of Dan Potter
    Dan Potter
    Participant

    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;-)

  • #25007
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

  • #25011
    Profile photo of Dan Potter
    Dan Potter
    Participant

    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?

  • #25032
    Profile photo of Martin Nielsen
    Martin Nielsen
    Participant

    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.

  • #25091
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

  • #25155
    Profile photo of Fred Fernandes
    Fred Fernandes
    Participant

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

  • #25158
    Profile photo of Don Jones
    Don Jones
    Keymaster

    5

  • #25159
    Profile photo of Fred Fernandes
    Fred Fernandes
    Participant

    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?

  • #25177
    Profile photo of Don Jones
    Don Jones
    Keymaster

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

You must be logged in to reply to this topic.