It's an array, so you're looking for Count to test for contents.

I'd recommend

$foo.count -gt 0

The "why" of this is related to how PSH handles comparison of collection objects

Answer from Taylor Bird on Stack Overflow
🌐
SPGuides
spguides.com › check-if-array-is-empty-in-powershell
How To Check If Array Is Empty In PowerShell?
January 23, 2024 - This method is useful if you want to filter out specific values (like $null or empty strings) before counting. # Create an array with a mix of null, empty, and non-empty strings $myArray = $null, "", "PowerShell", $null # Check if the array is empty after filtering out null and empty strings if ($myArray | Where-Object { $_ -ne $null -and $_ -ne "" } | Measure-Object).Count -eq 0 { Write-Host "The array is empty."
Discussions

hashtable - How to check if an associative array is empty in powershell - Stack Overflow
How do I check if $a above is empty (which it is). I would like to get $true as answer. ... That's not an associative array, it's a regular array, but the answer is the same. Use .Count and compare to 0. An associative array is called a [hashtable] in PowerShell and its literal form uses @{} ... More on stackoverflow.com
🌐 stackoverflow.com
What's the Value of an Empty Array?
I’m having a problem with the error routines I’m trying to rewrite for some scripts. The error codes are captured to arrays, and then used as parameters in if statements for reporting. If there are errors, then all is fine, but if everything works OK in the processes, the reporting errors out. More on community.spiceworks.com
🌐 community.spiceworks.com
7
4
August 3, 2018
System.Collections.Generic.List - What is the proper method for checking if a generic list of objects is null or empty?
Those are two different matters. A list being Null means that it has not been instantiated (remember lists are objects!). A list being empty means it is instantiated, but contains zero elements. Additionally, an instantiated list of type Object could of course contain Null elements, that's yet another matter. Note that it becomes more complicated if the list contains nested reference types (objects). You could then encounter scenarios where the "inner" reference type (object) gets set to Null without the list element that contains the nested object being actively modified. More on reddit.com
🌐 r/PowerShell
18
7
April 26, 2023
powershell - Check for empty value in Array - Stack Overflow
How do I check for empty values in an hashtable, and list the item name as well ? I could do if ($Vars.ContainsValue($null)) but this does not get me what item that has a $null value $Vars =... More on stackoverflow.com
🌐 stackoverflow.com
🌐
PowerShell Test-Path
powershellfaqs.com › check-if-an-array-is-empty-in-powershell
How to Check if an Array is Empty in PowerShell?
May 23, 2024 - To check if an array is empty in PowerShell, you can test if the count of the array is zero by using $array.Count -eq 0. If this condition returns $true, the array is empty; otherwise, it contains one or more elements.
🌐
Java2Blog
java2blog.com › home › powershell › check if array is empty in powershell
Check if Array is Empty in PowerShell [4 ways] - Java2Blog
November 21, 2023 - The following example creates an empty array in PowerShell. ... One of the simplest ways to check if an array is empty in PowerShell is by using the Count property.
🌐
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.
🌐
SharePoint Diary
sharepointdiary.com › sharepoint diary › powershell › powershell arrays › how to check if an array is empty in powershell?
How to Check If an Array is Empty in PowerShell? - SharePoint Diary
September 18, 2025 - Plus, it works consistently across different PowerShell versions. The Length property is another reliable way to check for empty arrays. It’s essentially interchangeable with Count in most cases. ... Personally, I tend to use count more often, but that’s just a force of habit. Both work equally well, so use whichever feels more natural to you. You can also nest conditions using else if in PowerShell, and this guide shows you how it’s done.
🌐
Collecting Wisdom
collectingwisdom.com › home › how to check if array is empty in powershell (with examples)
How to Check if Array is Empty in PowerShell (With Examples) - Collecting Wisdom
June 13, 2024 - This returns True, which tells us that the array named $my_array is indeed empty. We can use the following syntax to create an array named $my_array with no values and then use an if else statement to check if the array is empty, returning custom text as a result:
Find elsewhere
🌐
Surrounding The Code
surroundingthecode.wordpress.com › 2011 › 12 › 12 › powershell-nulls-empty-arrays-single-element-arrays
Powershell: nulls, empty arrays, single-element arrays | Surrounding The Code
July 1, 2016 - Here is the sample code. Try reading through this and predicting the output. (Don’t read the summary at the bottom of the code.) Then run it and see if you were right. # Compare the results of returning an empty array, a null, or any other single value function testEmptyArray { $x = @() # explicitly return an array, but the calling code determines the actual result return $x } function testNull { return $null } function testOneValue { return "The Value" } function testOneElementArray { return @("the element") } cls " ------------- return a NULL -------------" $a = testNull $a.gettype() | Sel
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › scripting › learn › deep-dives › everything-about-arrays
Everything you wanted to know about arrays - PowerShell | Microsoft Learn
If you're still on PowerShell 5.1, you can wrap the object in an array before checking the count to get an accurate count. if ( @($array).Count -gt 0 ) { "Array isn't empty" }
🌐
Reddit
reddit.com › r/powershell › system.collections.generic.list - what is the proper method for checking if a generic list of objects is null or empty?
r/PowerShell on Reddit: System.Collections.Generic.List - What is the proper method for checking if a generic list of objects is null or empty?
April 26, 2023 -

As the title states, what is the best/correct/preferred method for checking if a System.Collections.Generic.List of Objects is null or empty?

Do you just use Count?

If Count returns 0 then it’s empty?

I did some research and it wasn’t clear to me what the best approach was. Any advice/direction you can give would be greatly appreciated.

Thanks in advance!

🌐
Rakhesh
rakhesh.com › powershell › non-empty-arrays-and-properties
Non empty Arrays and properties – rakhesh.com
September 26, 2022 - One thing I usually do when checking whether the output of some cmdlet that I store in a PowerShell variable is empty or not is cast it into an array and check its count.
🌐
Powershelladmin
powershelladmin.com › wiki › Remove_empty_elements_from_an_array_in_PowerShell.php
Remove empty elements from an array in PowerShell - PowerShellAdmin.com
February 27, 2026 - Both $null and empty strings are considered false, so you can actually just throw the pipeline object into the Where-Object script block. Here we should get a count of two elements, the space and the letter, and we do. PS C:\> @(@("", " ", $null, "a") | Where { $_ }).Count 2 · I will demonstrate an explicit way as well. If you have integers with the numeric value "0" in the array, they will also be considered false, so if this is relevant, and you want to keep those, use this:
🌐
SharePoint Diary
sharepointdiary.com › sharepoint diary › powershell › how to check for null, not null, or empty in powershell?
How to Check for Null, Not Null, or Empty in PowerShell? - SharePoint Diary
September 28, 2025 - When working with arrays in PowerShell, it is important to understand how null and empty string values are handled. You can use the IsNullOrEmpty method to check if an array is null or empty.
🌐
GitHub
github.com › PowerShell › PowerShell › issues › 21547
I want return an empty array in a function, but it return a null value. · Issue #21547 · PowerShell/PowerShell
April 28, 2024 - Refer to Differences between Windows PowerShell 5.1 and PowerShell. I want return an empty array in a function, but it doesn't do it, which has an unintended effect. I also used the [array] cast type, which didn't work either. The problem is that since I explicitly specified its return type, it should not return any other type. Here, the Compare-Object error occurs because it does not return the expected array. Here I used -is to see if it was an array, and returned false.
Author   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 - You may have noticed that I always place the $null on the left when checking for $null in my examples. This is intentional and accepted as a PowerShell best practice. There are some scenarios where placing it on the right doesn't give you the expected result. Look at this next example and try to predict the results: if ( $value -eq $null ) { 'The array is $null' } if ( $value -ne $null ) { 'The array is not $null' }