I have a condition stored in a string variable and I want to use this in an if-statement.
In this example there is always a match, as the variable is not zero or null, etc. It's not "executing" the variable as condition.
My wish is to "execute" the condition what is stored in the variable.
$myCheckTest = '$test -eq 4'
$test = 5
if ($myCheckTest) {
write-host "TEST MATCH"
} else {
write-host "TEST NO MATCH"
}
This works without the quotes like: $myCheckTest = $test -eq 4 but the condition is externally stored in a json file.
I also tried if ( & {$myCheckTest} ) { as I think that this is comparable with JavaScript if ( eval(condition) ) but this is still not giving me the proper answer "TEST NO MATCH" that I expect.
I am aware of powershell IF condition in a Variable but here the condition is not in a string-variable like I have.