How to display the result of a function?

Tagged: ,

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 1 year, 9 months ago.

  • Author
    Posts
  • #22543
    Profile photo of Mason Emlen
    Mason Emlen
    Participant

    I know how to invoke a function, but how do I display the function result on screen?

  • #22544
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Whatever the function writes to the pipeline, by using Write-Output, will be returned as the result of the function. If nothing else is capturing that result, then it will display on the screen.

    Functions are a kind of PowerShell command, and can work very similarly to a cmdlet. So basically, you just run the function.

    function test {
      write-output "Hello"
    }
    test
    

You must be logged in to reply to this topic.