GurdeepS
GurdeepS

Reputation: 67213

Changing each entry in a list returned from powershell

I have a list of paths (filtered by special criteria). I want to mutate each entry in this list, but can't find a way (I think it's immutable). What's the best way of going about this?

Thanks

Upvotes: 0

Views: 88

Answers (1)

stej
stej

Reputation: 29449

I guess you have some collection, not only list (probably array).

PS> $myList = 'first','second','third'

You can mutate the collection by indexing or just by creating new array like this:

PS> $myList[1] = '2nd'
#or
PS> $myList | % { $_.Substring(0,2) }
  fi
  se
  th

Upvotes: 2

Related Questions