You guys are making this too hard. PowerShell handles this quite elegantly e.g.:

Copy> $str1 = $null
> if ($str1) { 'not empty' } else { 'empty' }
empty

> $str2 = ''
> if ($str2) { 'not empty' } else { 'empty' }
empty

> $str3 = ' '
> if ($str3) { 'not empty' } else { 'empty' }
not empty

> $str4 = 'asdf'
> if ($str4) { 'not empty' } else { 'empty' }
not empty

> if ($str1 -and $str2) { 'neither empty' } else { 'one or both empty' }
one or both empty

> if ($str3 -and $str4) { 'neither empty' } else { 'one or both empty' }
neither empty
Answer from Keith Hill on Stack Overflow
🌐
LazyAdmin
lazyadmin.nl › home › powershell – check if variable is null or empty
PowerShell - Check if variable is Null or Empty — LazyAdmin
April 9, 2024 - # Null variable $variableIsNull # Empty string variable $emptyString = "" # Empty array variable $emptyArray = @() There are a couple of ways to check if a variable or result is Null in PowerShell.
Discussions

Powershell command - null or empty comand is not working
case1 if(($RequestorEmail -ne $null) -or ($RequestorEmail -ne "")) case2 if ( -not [string]::IsNullOrEmpty( $RequestorEmail ) ) Windows for business | Windows Server | User experience | PowerShell · Windows for business | Windows Server | User experience | PowerShell ... In the situation you present, $RequestorEmail contains an empty ... More on learn.microsoft.com
🌐 learn.microsoft.com
2
0
August 13, 2021
Switch test for $null and empty string
Check this box if they match or the issue you are reporting is not version specific. https://learn.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-switch · I have not confirmed other versions, but assume this has always been the case. ... Notice that the empty string value doesn't match $null ... More on github.com
🌐 github.com
2
October 2, 2022
Best way to check for a null variable?
$null -ne $value If you are explicitly checking for null, this is what you want. Having null on the left catches some edge cases. If you just check on the variable, you are really checking if it is not true. Lots of values besides null match that. Everything you ever wanted to know about null More on reddit.com
🌐 r/PowerShell
33
29
August 10, 2019
Passing $null to a [string] parameter unconditionally causes conversion to [string]::Empty
Passing $null to any of these functions outputs $null. The only parameter type I haven't found a way to which to pass $null without conversion is [string]; PowerShell always converts $null to [string]::Empty. More on github.com
🌐 github.com
10
August 19, 2017
🌐
SID-500.COM
sid-500.com › 2021 › 07 › 07 › powershell-null-vs-isnullorempty
PowerShell: $null vs ::IsNullOrEmpty – SID-500.COM
July 7, 2021 - It’s just an empty string. Which brings me to $justempty. What will happen here? Oh, right, $justempty is really empty, so it is $null. Simply put, it is just nothing. Now we explore the ::IsNullOrEmpty statement. It’s a .NET statement to figure out, if a value is null or empty. Not surprisingly, both value show true, because the first one is empty and the second one is just nothing, so it is $null. Nice. Mission accomplished. Keep on working with PowerShell!
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › scripting › learn › deep-dives › everything-about-null
Everything you wanted to know about $null - PowerShell | Microsoft Learn
June 11, 2024 - PS> function Get-Nothing {} PS> $value = Get-Nothing PS> $null -eq $value True · $null values impact your code differently depending on where they show up. If you use $null in a string, then it's a blank value (or empty string).
🌐
Thinkpowershell
thinkpowershell.com › blog › test-powershell-variable-for-null-empty-string-and-white-space
Test PowerShell Variable for Null, Empty String, and White Space
October 25, 2017 - Our variable may truly be absent ... a value. If our variable is a string, it could contain a value of “”, which is an empty value as far as a string is concerned, but is still a value when compared to $null....
🌐
PowerShell Test-Path
powershellfaqs.com › powershell-isnullorempty
PowerShell IsNullOrEmpty() Example
July 29, 2024 - Null: Represents the absence of a value. In PowerShell, null is represented by $null. Empty: Refers to a string with no characters, represented by "" or [string]::Empty.
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 513246 › powershell-command-null-or-empty-comand-is-not-wor
Powershell command - null or empty comand is not working - Microsoft Q&A
August 13, 2021 - case1 if(($RequestorEmail -ne $null) -or ($RequestorEmail -ne "")) case2 if ( -not [string]::IsNullOrEmpty( $RequestorEmail ) ) Windows for business | Windows Server | User experience | PowerShell · Windows for business | Windows Server | User experience | PowerShell ... In the situation you present, $RequestorEmail contains an empty string.
Find elsewhere
🌐
SharePoint Diary
sharepointdiary.com › sharepoint diary › powershell › null in powershell: everything you need to know!
Null in PowerShell: Everything You Need to Know! - SharePoint Diary
September 20, 2025 - By using the [string]::IsNullOrEmpty() method, you can accurately determine if a string is null or empty, ensuring your scripts handle string comparisons correctly. Null values in arrays can be tricky.
🌐
ByteInTheSky
byteinthesky.com › home › powershell › how to check if a string is null or empty in powershell
How to Check If a String is Null or Empty in PowerShell - ByteInTheSky
December 26, 2022 - $str1 = $null if ([bool]$str1) ... are two ways to check whether a string is null or empty: using IsNullOrEmpty static method and casting the string to boolean....
🌐
SPGuides
spguides.com › check-if-a-variable-is-null-or-empty-in-powershell
How to Check if a Variable is Null or Empty in PowerShell?
May 7, 2025 - When specifically dealing with string variables, the .NET method [String]::IsNullOrEmpty() is perfect for checking if a string is null or empty.
🌐
miajimyu note
miajimyu.com › en › docs › powershell › powershell-tips › how-to-judge-null-and-empty
How to check for null and empty characters in variables in PowerShell | miajimyu note
August 9, 2020 - # Example 1 PS> $var = $null PS> ... # Example 3 PS> $var = "a" PS> if($var){"not null or empty"}else{"null or empty"} not null or empty · Use [String]::IsNullOrEmpty()....
🌐
GitHub
github.com › MicrosoftDocs › PowerShell-Docs › issues › 9255
Switch test for $null and empty string · Issue #9255 · MicrosoftDocs/PowerShell-Docs
October 2, 2022 - $values = '', 5, $null switch ( $values ) { '' { "Value '$_' is an empty string" ; continue } $null { "Value '$_' is `$null or an empty string" } default { "Value [$_] is not an empty string or `$null" } }
Author   MicrosoftDocs
🌐
Collecting Wisdom
collectingwisdom.com › home › how to check if string is empty in powershell (with examples)
How to Check if String is Empty in PowerShell (With Examples) - Collecting Wisdom
February 26, 2024 - A value of $null is considered to be empty. If a string has a value equal to ” then PowerShell will tell us that the string is empty: A string with beginning and ending quotes and nothing in between is considered to be empty because it contains ...
🌐
Powershellexplained
powershellexplained.com › 2018-12-23-Powershell-null-everything-you-wanted-to-know
Everything you wanted to know about $null - Powershell
December 23, 2018 - It is very common to check if a value is $null to see if the user provided a value or not. ... The $Value will be an empty string '' by default in this case if no value is provided.
🌐
Willpage
willpage.dev › 2023 › 02 › 21 › null-or-empty-string-coalesce-in-powershell-7
Null or Empty String Coalesce in PowerShell 7
February 21, 2023 - The exclamation mark in front of the string variable is a shortcut to the -not operator. This causes it to treat the variable as boolean where null or empty is False and having a non-zero length value is True.
🌐
HeelpBook
heelpbook.net › 2019 › powershell-variable-for-null-empty-string-and-white-space
Powershell – Variable for Null, Empty String and White Space
April 2, 2019 - Our variable may truly be absent ... for which we do not set a value. If our variable is a string, it could contain a value of “”, which is an empty value as far as a string is concerned, but is still a value when compared to $null....
🌐
GitHub
github.com › PowerShell › PowerShell › issues › 4616
Passing $null to a [string] parameter unconditionally causes conversion to [string]::Empty · Issue #4616 · PowerShell/PowerShell
August 19, 2017 - Passing $null to any of these functions outputs $null. The only parameter type I haven't found a way to which to pass $null without conversion is [string]; PowerShell always converts $null to [string]::Empty.
Author   PowerShell