How to check if an associative array is empty in powershell How to check if an associative array is empty in powershell powershell powershell

How to check if an associative array is empty in powershell


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 @{} (curly braces).

@{}.Count -eq 0  # hashtable (associative array)@().Count -eq 0  # array


Arrays have Count property, and you can check if this value is 0. So the condition you would check for is

$a.Count -eq 0