PowerTip: Retrieving Specific Items from Hash Table

Doctor Scripto

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

0 comments

Discussion is closed.

Feedback usabilla icon