A Powershell Array of Hashtables instead of a Multidimensional Array

When scripting and coding a solution we’re often required to read from back-end databases.  Sometimes if we want to reduce the amount of ‘reads’ to the database (if, for example, we know the information isn’t going to change very frequently) or we want faster access by storing the data in-memory, we may choose to write all the information we’ve retrieved from the database into an array.

 

Once we’ve stored the data inside our (multidimensional) array, retrieving a particular record is sometimes an obstacle.  Particularly when we’re using unnamed indexes to reference records and array dimensions.  To circumvent this issue, I like to store my records in an (single dimension) array of hashtables!  This allows me to retrieve records very easily based on specific hashtable names!

 

1 thought on “A Powershell Array of Hashtables instead of a Multidimensional Array

  1. Excellent.  Amazing how many articles on Arrays and Hash tables that do not provide a clear explanation of retrieving a record.  THANK YOU!

Leave a Reply

Your e-mail address will not be published. Required fields are marked *

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