Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert the result of select to array

Tags:

powershell

I have the following code.

$l = @("A", "B", "X", "Y")
echo "A,B,X`n1,2,3,4" > .\myFile # Create test file

$f = cat myFile | ConvertFrom-Csv | gm -MemberType NoteProperty | select Name
compare $l $f

$a = .... # convert $f to array
compare $l $a

How to convert the $f to array so it can be compared with an array? Bracing @(...) doesn't work.

I got the following result when compare $l and $f.

PS C:\Users\nick> compare $l $f

InputObject                                                 SideIndicator
-----------                                                 -------------
@{Name=A}                                                   =>
@{Name=B}                                                   =>
@{Name=X}                                                   =>
A                                                           <=
B                                                           <=
X                                                           <=
Y                                                           <=
like image 485
ca9163d9 Avatar asked Feb 17 '23 10:02

ca9163d9


1 Answers

Replace select Name with select -Expand Name or ForEach-Object { $_.Name }.

like image 109
Ansgar Wiechers Avatar answered Feb 26 '23 19:02

Ansgar Wiechers