arrayspowershellmultiplication

powershell - multiply each value in array


how can i multiply each value by 10 in an array? the given array is

[int]$arr = 0..1000

now the way i have tried to solve it is:

foreach($valuex10 in $arr)
{
      $valuex10 = $valuex10 * 10
}

I think that should work, but it does not, i get the error "cant convert to System.Int32" if i try to give every variable the [int] (tag?) the ISE tells me it cant process it because there is no variable to start with. So what is wrong?

creating a new array is not allowed.


Solution

  • You can use this:

    $arr = 0..1000
    for($i = 0; $i -lt $arr.Length; $i++){
        $arr[$i] = $arr[$i] * 10
    }