if operator (not) in PowerShell

I do miss the if operator (?:) that I have in C++, C#, JavaScript and likewise but not in PowerShell.

A quick workaround is the subexpression ($()) in a string surrounded by ".

$ref = 'blue'
"The color is $(if ($ref -eq 'blue'){''} else{'not '})blue."

The output is
The color is blue.

If the $ref value is changed
$ref = 'yellow'
The output is
The color is not blue.


wikipedia: ?:

1 comment:

narayana p said...

I feel satisfied to read your blog, you have been delivering a useful & unique information to our vision even you have explained the concept as deep clean without having any uncertainty, keep blogging. SQL server dba Online Training