<!-- language-all: sh -->
Many good answers here; let me offer a **pragmatic summary** with **PowerShell-idiomatic solutions**:
Given a variable `$str` that may contain `$null` or a *string* (or any _scalar_):
```
# Test for $null or '' (empty string).
# Equivalent of: [string]::IsNullOrEmpty($str)
$str -like ''
# Test for $null or '' or all-whitespace.
# Equivalent of: [string]::IsNullOrWhitespace($str)
$str -notmatch '\S'
```
Note: If `$str` can be a _collection_ (array), use the type-agnostic solutions at the bottom.
* Using the string-only [`-like`](
[To see links please register here]
) operator implicitly coerces the LHS to a _string_, and since `[string] $null` yields the empty string, both `'' -like ''` and `$null -like ''` yield `$true`.
* Similarly, the [regex](
[To see links please register here]
[`-match` / `-notmatch`](
[To see links please register here]
) operators, as *string-only* operators, coerce their LHS operand to a string, and `$null` is treated like `''` in this conversion.
* `\S` is a regex escape sequence that matches any _non_-whitespace character (it is the negated form of `\s`).
* `-match` / `-notmatch` perform _substring_ matching by default (and only ever return _one_ match), so if `\S` matches, the implication is that at least one character that isn't a whitespace character is present.
---
**Caveat**:
Given PowerShell's dynamic typing, you may not know the type of the value stored in a given variable ahead of time.
While the techniques above work predictable with `$null`, `[string]` instances, and other types that are _non-enumerable_, **_enumerable_ values (other than strings) may yield surprising results**, because if the LHS of `-like` and `-notmatch` are enumerables (loosely speaking: collections), the operation is applied to _each element_, and instead of returning a single Boolean value, the _sub-array of matching elements_ is returned.
In the context of a conditional, the way an array is coerced to a Boolean is somewhat counterintuitive; if the array has just _one_ element, that element itself is coerced to a Boolean; with _two or more_ elements, the array is always coerced to `$true`, irrespective of the element values - see the bottom section of [this answer](
[To see links please register here]
). For instance:
```
# -> 'why?', because @('', '') -like '' yields @('', ''), which
# - due to being a 2-element array - is $true
$var = @('', '')
if ($var -like '') { 'why?' }
```
if you **cast a non-string enumerable LHS to `[string]`**, PowerShell stringifies it by space-concatenating its (stringified) elements.
This is also what happens _implicitly_ when you call `[string]::IsNullOrEmpty()` or `[string]::IsNullOrWhiteSpace()`, because their parameter is `[string]`-typed.
Thus, the **type-agnostic equivalents of the above** - using the stringification rules described - are:
```
# Test for $null or '' (empty string) or any stringified value being ''
# Equivalent of: [string]::IsNullOrEmpty($var)
[string] $var -eq ''
# Test for $null or '' or all-whitespace or any stringified value being ''
# Equivalent of: [string]::IsNullOrWhitespace($var)
([string] $var).Trim() -eq ''
```