mikeydk
asked on
Powershell - Add to array
Hey
$example = ("AAA", "BBB", "CCC")
function calc {
param ()
return "test1"
}
$example | % { calc }
How do I add the value from calc to the array? (ext. the array - not just string concatenate)
AAA TEST1
BBB TEST1
CCC TEST1
Mike
$example = ("AAA", "BBB", "CCC")
function calc {
param ()
return "test1"
}
$example | % { calc }
How do I add the value from calc to the array? (ext. the array - not just string concatenate)
AAA TEST1
BBB TEST1
CCC TEST1
Mike
you are moving from a 1 dimensional array to a 2 dimensional array.
You mean as another "column"? That would need an array of objects, e.g. of arrays. What do you want to do with the result?
Maybe a trick:
function calc {
param ()
return "test1"
}
$example = ("AAA", "BBB", "CCC")
$count = $example.count
$count = $count -1
$array = 0..$count | foreach-object{
$example[$_]| foreach-object {new-object psobject -property @{ $_ = calc $_}}
}
try
$array | select-object AAA
$array | fl
function calc {
param ()
return "test1"
}
$example = ("AAA", "BBB", "CCC")
$count = $example.count
$count = $count -1
$array = 0..$count | foreach-object{
$example[$_]| foreach-object {new-object psobject -property @{ $_ = calc $_}}
}
try
$array | select-object AAA
$array | fl
ASKER
David Johnson, CD, MVP> Yes ;)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.