Quantcast
Viewing all articles
Browse latest Browse all 34890

PowerTip: Get the Number of Items in a Hash Table

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

Image may be NSFW.
Clik here to view.
Hey, Scripting Guy! Question
 How can I find the number of key/value pairs that a Windows PowerShell hash table contains?

Image may be NSFW.
Clik here to view.
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

Image may be NSFW.
Clik here to view.

Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 34890

Trending Articles