Functions and object best practices

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Dave Wyatt Dave Wyatt 1 year, 1 month ago.

  • Author
  • #40161
    Profile photo of Paul Cassidy
    Paul Cassidy

    Should functions only take inputs to object method and the object, call those methods and return values if any or should functions also return properties values from the input object

  • #40165
    Profile photo of Dave Wyatt
    Dave Wyatt

    I don't really understand the question. Can you give examples of what you're comparing?

  • #40179
    Profile photo of Don Jones
    Don Jones

    Functions should take input only to their parameters. Whether you're passing in an entire object or individual values depends on the situation. Many cmdlets (like Set-Service) can do both.

    Functions should produce objects as output. If a function is doing something and not producing any output, you can optionally implement a -PassThru parameter (again, see Set-Service) so that your function can output its original input for the rest of the pipeline to deal with.

You must be logged in to reply to this topic.