I am trying to create a new variable that would use other variable with dynamic name as its value. Here's what I am trying to do:
I have a System.Array with two values:
$Years = 2015, 2016
Another variable $Transactions has a list of various transactions.
I am trying to use each of those $Years values in the following way:
ForEach($Year in $Years){
New-Variable -Name "Transactions_$Year" -Value $Transactions | Where {$_.Date -like "*.$Year"
Now what I would like to do (within that same ForEach-loop) is to use that $Transactions_$Year value when I am creating a another new variable, like this:
New-Variable -Name "Income_$Year" -Value $Transactions_$Year | Where {$_.Amount -NotLike "-*"} | Measure-Object Amount -Sum | Select -ExpandProperty Sum
}
Is this possible, or do you have any alternative ways how I could achieve this?
See Question&Answers more detail:os