$a = "-eq"
$b = "-lt"
$c = "-gt"
$op = $a
if ((Invoke-expression "3 $op 3")) { #<=== How do I convert this so it see's -eq and does the operation??
write-host "equal"
}
Powershell Replace variable with operator
Alain Jetté
21
Reputation points
Hi.
I have just started using powershell. I google and search the help from powershell, but just don't seem to find what I am looking for.
Don't know how to go about this.
lets say I have this code:
$a = "-eq"
$b = "-lt"
$c = "-gt"
$op = $a
if (3 $op 3) { #<=== How do I convert this so it see's -eq and does the operation??
write-host "equal"
}
How can I use $op so it does the operation?
I need to convert it from string to operator?
Do I have to set the variable as something else than a string.
Thank you.
Windows for business | Windows Server | User experience | PowerShell
Answer accepted by question author
MotoX80
37,686
Reputation points