Why don't you just convert your HashTable values to a String Array and then compare them both?
Convert your values stored in HashTable to a String array:
$hashTableValues = $remotefilehash.Values.ForEach('ToString')
Then, simply compare both the String arrays ($localmd5 and $hashTableValues) and get your unique values using Select-Object cmdlet:
Compare-Object -ReferenceObject $localmd5 -DifferenceObject $hashTableValues | Where-Object { ($_.SideIndicator -eq '=>')} | Select-Object InputObject
As per your updated question:
You can fetch the keys you're interested in by doing something like this:
$requiredKeys = Compare-Object -ReferenceObject $localmd5 -DifferenceObject ($remotefilehash.Keys.GetEnumerator() -join ',').Split(' ') | Where-Object { ($_.SideIndicator -eq '=>')} | Select-Object InputObject
Then, you can convert these keys to an array of strings:
$keysAsString = $requiredKeys | Foreach {"$($_.InputObject)"}
Now, since you've got the list of keys for which you want the values, you can use these keys as indexes and fetch the required values from HashTable:
foreach($key in $keysAsString)
{
foreach($hKey in $remotefilehash.Keys)
{
if($hKey.ToString() -eq $key)
{
Write-Output $hash[$hKey] #use the value accordingly
}
}
}
| select-object $remotefilehash.valuesbut only the ones that get passed from the where step