r/PowerShell • u/iBloodWorks • Jan 22 '26
5.1 vs 7.5 select from hashtables
Hi,
I have this snippet
$out = foreach ($prc in $prcs){
@{
Name = $prc.Name
Handles = $prc.Handles
Time = get-date -Format FileDateTimeUniversal
}
}now,
If I want to select Name, Handles, Time 5.1 will just return nothing (?)
7.5 will return the expected data as a table
how can i achieve the same result in 5.1 as clean as possible (one liner preferable)
probably by playing around with $out.GetEnumerator() (?)
thanks :)
ai gave a bunch of jibberish (granted my company ai which i have access to right now is ass)
i found this topic online as well but not with the exact same problem / solution
15
Upvotes
20
u/Thotaz Jan 22 '26
If I understand you correctly, then replace
@{with:[pscustomobject]@{5
u/surfingoldelephant Jan 22 '26
Unless you need the intermediary hash tables for another purpose, you can achieve the same result with:
Or as a single line:
If you truly need an array of hash tables in
$out:2
u/z386 Jan 22 '26
If you already have an array of hashtables in $out like in your example, you could convert it to objects with:
2
u/da_chicken Jan 22 '26
I don't entirely understand what you're trying to get because you don't unambiguously explain what you want your output to be at all.
But, I would do it like this:
1
u/[deleted] Jan 22 '26
[removed] — view removed comment