Search for a key in hashtable and average associated values Powershell

Question:

So I have a script where I’m trying to get the test name and store it into a hashtable as the key, then get a high test score and a low test score and store those 2 as the values. Then, I would like to take and allow the user to search for a test name and see the high and low scores. what I have currently is:

This code successfully stores the high and low scores to that test name, but I need a way to find the name of the test with the $search value. Then average the two test scores stored in the values part.

Answer:

It depends on how you want to use it, but there are several ways:

That will return a $true/$false if the key exists.

You can also iterate through the keys:

You could just reference it:

You can choose the way to reference/use it that best suits your needs.

Source:

Search for a key in hashtable and average associated values Powershell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply