Quantcast
Channel: Hey, Scripting Guy! Blog
Viewing all articles
Browse latest Browse all 3333

PowerTip: Retrieving Specific Items from Hash Table

$
0
0

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


Viewing all articles
Browse latest Browse all 3333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>