September 30th, 2014

PowerTip: Retrieving Specific Items from Hash Table

Doctor Scripto
Scripter

Summary: Retrieve specific items from a Windows PowerShell hash table. Hey, Scripting Guy! Question How can I use Windows PowerShell t retrieve specific values associated with specific keys in a hash table?

Hey, Scripting Guy! Answer Suppose you have a hash table such as this:

$d = @{a=28;b=29;c=30}

The keys and values associated with the hash table are:

PS C:> $d  

Name                           Value                                          

—-                           —–                                          

c                              30                                             

b                              29                                             

a                              28          

You can retrieve by name (key) property by using the item method or by directly supplying the key.

  Note  Key names are letters, and to retrieve via the names, you must enclose the letters in quotation marks.

PS C:> $d.Item(‘a’)

28  

PS C:> $d[‘a’]

28

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.

Feedback