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 6 months, 2 weeks ago.

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

    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
    Moderator

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

  • #40179
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.