Is there a shorthand for the IF statement in PowerShell?

Question:

In bash, I often did things like:

Instead of creating a full-fledge if statement:

Is there a similar shorthand in PowerShell without creating a function or alias?

I’d rather not write the following in PowerShell:

Answer:

If seems more readable to me, but you can use short circuit of OR (similar to BASH version):

Source:

Is there a shorthand for the IF statement in PowerShell? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply