How can I enumerate a hashtable as key-value pairs / filter a hashtable by a collection of key values
<p><sup>
<strong>Editor's note:</strong>
This question has a complicated history, but boils down to this:<br>
* To learn how to <strong><em>enumerate</em> the entries of a hashtable by its <em>key-value pairs</em></strong>, see <a href="https://stackoverflow.com/a/37635938/45375">the accepted answer</a>.<br>
* To learn how to <strong><em>filter</em> a hashtable by a <em>collection of key values</em></strong>, see <a href="https://stackoverflow.com/a/37636001/45375">the other answer</a>.
</sup></p>

<hr>

<p>I think I fell into the X Y problem again, my initial question was about Filtering a hash table. I discovered it's easier to filter before creating the hash table. Question answered, right?</p>

<p>Nope, the Y problem was looping each Key and using the Values which @briantist helped me with.</p>

<p>My goal is to loop over the key names, which are timestamps, and schedule a task using the key name as the task name and trigger.</p>

<p>I'm creating a hash table from a CSV file using <code>Group-Object -AsHashTable -AsString</code>  <strong>-edit, it's worth mentioning here that filtering the CSV before creating the HashTable only makes things easier down the <code>Pipeline</code> or script</strong>.  </p>

<p>As an example:</p>

<pre><code>Import-CSV (ls -path D:\ -Filter source*.csv | sort LastWriteTime | Select -Last 1).FullName |
 where {$_.TimeCorrected -ne 'ManualRebootServer'} |
 group TimeCorrected -AsHashTable -AsString
</code></pre>

<p>I'm trying to loop over the key names and able to display the key names using:</p>

<pre><code>$var = Import-Csv csv123.csv | Group-Object Value1 -AsHashTable -AsString

foreach ($key in $var.Keys){"The key name is $key"}

#Create a scheduled task named and triggered based on the HashTable keyname
#test test test
foreach ($key in $var.keys){IF($key -ne 'ManualRebootServer'){"Register-ScheduledJob"}}
</code></pre>

<p>I'm just not sure how to get the values from the keys I am interested in.</p>

<p>I've found the following works, but only when I enter a Key name manually.  I'm just unsure how to combine both loops.</p>

<pre><code>($val.GetEnumerator() | Where {$_.key -eq '06-11-16 18:00'} | ForEach-Object { $_.value }).Server
</code></pre>