Display the Hash Table

Displaying a hash table if fairly easy.  What we want to do in our script is to have the user make a selection based on what was displayed.  This is also fairly easy, but it adds another layer to the script which can make it look a little odd.

First, $len (short for length) gets a count of the rows of the table.  We use this for a few tasks like asking the user to make a selection between 1 and $len.  More importantly, we use this as part of a While loop that keeps running if they type a value higher than the total number of rows (ex: if the option is to choose 1 - 5 and they type 50, the While loop will continue).

Next, we initialize a variable called $menuChoice that will be used in the Switch a little later.  

Then we create a While loop so that we can force to user to make a valid selection (ex: if the option is to choose 1 - 5, we will show the table again if they type "apple" )

$($hash.GetEnumberator() | sort key | out-string) is actually what generates the hash table. 

Finally, once they make a selection, $selected records what they selected.



No comments:

Post a Comment