Returning multiple values from a PowerShell function

Returning multiple values in a powershell function is something that took me an embarrassing amount of time to figure out. Its not documented all that well and there are very few blog posts on the topic. It turns out there are a few ways to do this but I keep falling back to using hashtables, they are the most dynamic and pretty much anything can be returned with almost no issues. Below is a very simple example of how to make this work.

  1. Create a hashtable with: “[hastable]$varname = @{}”.
  2. Then do all of the work you need done and save your results in a property that you would like.
  3. Return the parent variable name and then you are able to access it via the properties you made.

Hope this helps!


4 comments… add one
  • Venkatesh Link Reply

    Yes It helps me lot

  • G6 Link Reply

    Thanks man this helped.

  • Carmoisine Link Reply

    Exactly what I was looking for, thank you 🙂

  • shan Link Reply

    THANK YOU very much…
    this helps me lot lot lot more

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.