views:

45

answers:

1

anyone know how to evalute a string twice in powershell?

from example $l1 = yes $l2 = no

for (i=0;i -lt 2; i++) { echo $1$i }

+2  A: 

If I understand the question correctly then this code may do the job:

$l1 = 'yes'
$l2 = 'no'

# make and evaluate the expression:
for ($i = 1; $i -le 2; $i++) {
    Invoke-Expression "`$l$i"
}

# or, to be embedded into a string:
for ($i = 1; $i -le 2; $i++) {
    @"
Value is: $(Invoke-Expression "`$l$i")
"@
}
Roman Kuzmin
Invoke-Expression "`$l$i" was exactly what i was looking for! thanks
Bebuuk
Then why not to accept the answer? ;)
stej