Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why select -index array doesn't work, powershell

i need to add numbers that don't belong to a linear sequence to retrieve specified indexed folders, i make this attempts :

$a =ls | ?{$_.psiscontainer} | sort creationtime

Then i try to select only some of the folders(fail):

$a | select -Index (100, 101, (103..109))

Whit this simplified array i don't have problems:

$a | select -Index (103..109)

how can i add those numbers?

I try this, forcing the conversion to an array, but the process of conversion fails and i don't know why, if i get the type of the inner members of the array they are already Int32, so i don't understand the error.

$a | select -Index @(100, 101, (103..109))
like image 225
mjsr Avatar asked Dec 05 '25 08:12

mjsr


1 Answers

Parameter -Index is of type int[]. That means that what you pass in as an argument, it has to be an array of numbers.

Imho the simplest way is just to add the arrays like this:

0..100 | select -Index (2,3,5 + 20..30 + 50,60)

Note that you don't have to do ((2,3,5) + (20..30) + (50,60)), because the comma operator has higher priority than plus and interval operator.

like image 197
stej Avatar answered Dec 08 '25 04:12

stej