Ternary operator in PowerShell

From what I know, PowerShell doesn’t seem to have a built-in expression for the so-called ternary operator.

For example, in the C language, which supports the ternary operator, I could write something like:

<condition> ? <condition-is-true> : <condition-is-false>;

If that doesn’t really exist in PowerShell, what would be the best way (i.e. easy to read and to maintain) to accomplish the same result?

14 Answers
14

Leave a Comment