Create HashTable? With 2 Values

Welcome Forums General PowerShell Q&A Create HashTable? With 2 Values

Viewing 3 reply threads
  • Author
    Posts
    • #222081
      Participant
      Topics: 6
      Replies: 10
      Points: 103
      Rank: Participant

      Hi,

      I think i need a hash table for this?
      I would like a script to loop through a hash table and for each line, pass the values to my function.

      I have a working solution for 2 columns or a key and a value i believe?:

      [/crayon]

      My issue is trying to add a second value, I would like the list to have 3 columns which i believe would be a key and 2 values?

      Example (which im sure is not how i should do it):

      [/crayon]

       

      Any help on achieving this would be much appreciated.

       

      Thanks

      Jamie

      • This topic was modified 4 months, 3 weeks ago by JDobbsy1987.
    • #228499
      Participant
      Topics: 0
      Replies: 37
      Points: 371
      Helping Hand
      Rank: Contributor

      Hello Jamie,

      When you add second value,  your hash table values become arrays and you can access them using index.

       

       

    • #228505
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      A good old plain CSV file provides the same results and is much less complex I think.

    • #228961
      Participant
      Topics: 13
      Replies: 1753
      Points: 3,136
      Helping Hand
      Rank: Community Hero

      Hash tables have their uses, but Powershell most uses PSObject, which from a basic standpoint is an array of hashtables. Take a look at these basic examples:

      When anything is imported, it is typically generating a PSObject, such as Import-CSV. Without seeing the function it’s hard to assist, but the name of params (while I’m sure it’s just an example) is more of a type than a proper param name. If you look at this, you can see how an imported CSV is processed by the function:

      But you can even use the pipeline rather than the loop, as simple as this:

      Both produce the same output:

      However, when I see ‘balance’, you can also do something like this:

Viewing 3 reply threads
  • The topic ‘Create HashTable? With 2 Values’ is closed to new replies.