I'm trying to collect some info from remote hosts in form of a CSV string. I need the values to be returned in particular order to accumulate them in one CSV file.
I use ordered hash table to keep keys in particular order, but when I pass it to a remote host the order gets broken.
Is there a way to preserve the order?
$ordered_hash = [ordered]@{"a" = 1; "b" = 2; "c" = 3}
$ordered_hash
$scriptblock = {
param ($hash)
$hash
}
Invoke-Command -ComputerName localhost -ScriptBlock $scriptblock -ArgumentList ([hashtable]$ordered_hash)
Returns:
Name Value
---- -----
a 1
b 2
c 3
c 3
b 2
a 1