3

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))

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks i didn't knew the add operator for arrays, that is all that i need
2

For this example, you can get the same result using array slicing:

$a[100,101 + 103..109]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.