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 }
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 }
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")
"@
}