I'm looking for some clean and efficient way to compare arrays stored in hashtable, without iterating over them ideally. Also without harcoding the keys
The hashtable:
Key : somekey1
Value : {value1, value2, value3, value4}
Name : somekey1
Key : somekey2
Value : {value1, value2, value3}
Name : somekey2
created with:
$hashtable = @{};
$hashtable[somekey1] = @();
$hashtable[somekey2] = @();
$hashtable[somekey3] = @();
ForEach ($key in $hashtable.keys)
{
$hashtable[$key] += value1;
}
I would like to call something like:
Compare-Object $($hashtable.keys)[0] $($hashtable.keys)[1] -Property Value;
and the expected output would be
value4
Is this possible? (asking as a PowerShell newbie)
@{ somekey1 = 'value1', 'value2', 'value3', 'value4'; somekey2 = 'value1', 'value2', 'value3' }or actually a PSCustomObject/object list? Please try to create a minimal reproducible example in your question.$hashtable = @{};and then adding arrays like$hashtable[somekey1] = @();-> then filling with$hashtable[somekey1] +1 value1;$HashTable = @{ somekey1 = 'value1', 'value2', 'value3', 'value4'; somekey2 = 'value1', 'value2', 'value3' };Compare-Object $HashTable.somekey1 $HashTable.somekey2? if that doesn't answer the question, I suggest you edit your question and add an actual example (not a description) of how you create the hashtable.$Ordered = [ordered]@{ somekey1 = 'value1', 'value2', 'value3', 'value4'; somekey2 = 'value1', 'value2', 'value3' };Compare-Object $Ordered[0] $Ordered[1]. Or do you want compare each key with any other key?