July 19th, 2013

PowerTip: Get the Number of Items in a Hash Table

Doctor Scripto
Scripter

Summary: Learn how to get the number of items in a Windows PowerShell hash table.

Hey, Scripting Guy! Question How can I find the number of key/value pairs that a Windows PowerShell hash table contains?

Hey, Scripting Guy! Answer Use the Count property:

PS C:\> $hash = @{‘a’ = 1; ‘b’ = 2; ‘c’ = 3; ‘d’ = 4}

PS C:\> $hash

 

Name                           Value

—-                           —–

c                              3

d                              4

b                              2

a                              1

 

PS C:\> $hash.Count

4

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.