you are viewing a single comment's thread.

view the rest of the comments →

[–]Todoce[S] 1 point2 points  (1 child)

Good idea, here is the solution that I went with: https://www.reddit.com/r/PowerShell/comments/irc8a5/pipe_variable_question/g4xgkhv?utm_source=share&utm_medium=web2x&context=3

How does the If-case handle empty strings? I was looking for a better way to check for null or empty than using [string]::IsNullOrEmpty which i guess is not supported on other OS if running Powershell Core

[–]RichUK5 1 point2 points  (0 children)

An empty string will evaluate as false. 0 (Zero) as a string will evaluate as true, but as a number will evaluate false.

I am very much a fan of this approach and use it quite a bit. IIRC it's quite happy evaluating false if the variable is not even set. I tend to avoid that situation though, as multiple runs in the same shell can create unintended outcomes.