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:
$testInfo = @{}
$testName = read-host "Please enter the name of the test"
$testHigh = read-host "Please enter the high score of the test"
$testLow = read-host "Please enter the low score of the test"
$testInfo.Add($testName, $testHigh + " " + $testLow
$search = read-host "Please enter the name of the test you'd like to view the average score of"
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.
It depends on how you want to use it, but there are several ways:
$testInfo.ContainsKey($search)
That will return a $true
/$false
if the key exists.
You can also iterate through the keys:
foreach($key in $testInfo.Keys.GetEnumerator()) {
$key
}
You could just reference it:
$testInfo[$search]
# or
$testInfo.$search
You can choose the way to reference/use it that best suits your needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With