{"id":13401,"date":"2011-07-07T00:01:00","date_gmt":"2011-07-07T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2011\/07\/07\/use-powershell-hash-tables-with-your-cmdlets\/"},"modified":"2011-07-07T00:01:00","modified_gmt":"2011-07-07T00:01:00","slug":"use-powershell-hash-tables-with-your-cmdlets","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-hash-tables-with-your-cmdlets\/","title":{"rendered":"Use PowerShell Hash Tables with Your Cmdlets"},"content":{"rendered":"<p><b>Summary<\/b>: Learn how to Use Windows PowerShell hash tables with your cmdlets to create powerful commands.<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\" \/>Hey, Scripting Guy! I think I understand hash tables after having read your earlier articles about working with hash tables. What I do not understand is how hash tables work within Windows PowerShell commands. In addition, how do I find Windows PowerShell cmdlets that use hash tables?<\/p>\n<p>&mdash;JB<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\" \/>Hello JB,<\/p>\n<p>Microsoft Scripting Guy Ed Wilson here. I spent the Fourth of July playing with Windows PowerShell. The Scripting Wife spent the holiday reading. We both had a great holiday, and we were able to do exactly what we wanted to do for three days&mdash;it was wonderful.<\/p>\n<p><b>Note&nbsp; <\/b>&nbsp;This is the fourth (and last) blog post in a series of posts discussing the hash table. The <a href=\"http:\/\/blogs.technet.comhttps:\/\/devblogs.microsoft.com\/scripting\/learn-the-basics-of-powershell-hash-tables\/\">first post<\/a> covered the basics of working with hash tables such as creating a hash table, and adding and removing items from a hash table. The <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/07\/05\/automatically-create-a-powershell-hash-table.aspx\">second post<\/a> went into more detail and discussed programmatically adding items to the hash table, counting items in a hash table, and clearing the contents of the hash table. In the <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/07\/06\/use-a-powershell-hash-table-to-simplify-file-backups.aspx\">third post<\/a>, I talked about using a hash table to filter lists by removing duplicate items. In today&rsquo;s post, I discuss using hash tables with Windows PowerShell cmdlets.<\/p>\n<p>One of the things I did was play around with my <b>Get-Help<\/b> trick of searching the help contents for specific words (I discussed this trick in the article on <a href=\"http:\/\/blogs.technet.comhttps:\/\/devblogs.microsoft.com\/scripting\/learn-the-basics-of-powershell-hash-tables\/\">Monday<\/a> in which I detailed the four matching rules that <b>Get-Help<\/b> utilizes.) To find all of the mentions of hash tables in help, I used several different commands. The commands and their associated output appear here (the command <b>Get-Help Hash-Table<\/b> is not shown here because I ran it on Monday and the output appears in that article).<\/p>\n<p style=\"padding-left: 30px\">PS C:\\hsgTest&gt; Get-Help hashtable&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"><span style=\"text-decoration: underline\">Name<\/span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">Category<\/span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">Synopsis<\/span><\/p>\n<p style=\"padding-left: 30px\">Get-WinEvent&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cmdlet&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Gets events from event logs and event tracing log files on local and rem&#8230;<\/p>\n<p style=\"padding-left: 30px\">New-WSManSessionOption&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cmdlet&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Creates a WS-Management session option hash table to use as input parame&#8230;<\/p>\n<p style=\"padding-left: 30px\">ConvertFrom-StringData &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cmdlet&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Converts a string containing one or more key\/value pairs to a hash table.<\/p>\n<p style=\"padding-left: 30px\">Group-Object&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cmdlet&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Groups objects that contain the same value for specified properties.<\/p>\n<p style=\"padding-left: 30px\">about_Arithmetic_Operators&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HelpFile &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Describes the operators that perform arithmetic in Windows PowerShell.<\/p>\n<p style=\"padding-left: 30px\">about_hash_tables&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HelpFile &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Describes how to create, use, and sort hash tables in Windows PowerShell.<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">PS C:\\hsgTest&gt; Get-Help &#8220;hash table&#8221;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"><span style=\"text-decoration: underline\">Name<\/span>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">Category<\/span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">Synopsis<\/span><\/p>\n<p style=\"padding-left: 30px\">Get-WinEvent&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cmdlet&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Gets events from event logs and event tracing log files on local and rem&#8230;<\/p>\n<p style=\"padding-left: 30px\">New-WSManSessionOption&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cmdlet&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Creates a WS-Management session option hash table to use as input parame&#8230;<\/p>\n<p style=\"padding-left: 30px\">New-ModuleManifest&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cmdlet&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Creates a new module manifest.<\/p>\n<p style=\"padding-left: 30px\">Format-Table&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cmdlet&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Formats the output as a table.<\/p>\n<p style=\"padding-left: 30px\">ConvertFrom-StringData &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cmdlet&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Converts a string containing one or more key\/value pairs to a hash table.<\/p>\n<p style=\"padding-left: 30px\">Get-Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cmdlet&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Gets the current date and time.<\/p>\n<p style=\"padding-left: 30px\">Import-LocalizedData&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cmdlet&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Imports language-specific data into scripts and functions based on the U&#8230;<\/p>\n<p style=\"padding-left: 30px\">Select-Object&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cmdlet&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Selects specified properties of an object or set of objects. It can also&#8230;<\/p>\n<p style=\"padding-left: 30px\">Group-Object&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cmdlet&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Groups objects that contain the same value for specified properties.<\/p>\n<p style=\"padding-left: 30px\">Sort-Object&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cmdlet&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sorts objects by property values.<\/p>\n<p style=\"padding-left: 30px\">Select-XML&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cmdlet&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Finds text in an XML string or document.<\/p>\n<p style=\"padding-left: 30px\">Set-WmiInstance&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cmdlet&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Creates or updates an instance of an existing Windows Management Instrum&#8230;<\/p>\n<p style=\"padding-left: 30px\">about_Arithmetic_Operators&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HelpFile &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Describes the operators that perform arithmetic in Windows PowerShell.<\/p>\n<p style=\"padding-left: 30px\">about_Assignment_Operators&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HelpFile &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Describes how to use operators to assign values to variables.<\/p>\n<p style=\"padding-left: 30px\">about_Automatic_Variables&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HelpFile &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Describes variables that store state information for Windows PowerShell.<\/p>\n<p style=\"padding-left: 30px\">about_data_sections&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HelpFile &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Explains Data sections, which isolate text strings and other read-only<\/p>\n<p style=\"padding-left: 30px\">about_hash_tables&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HelpFile &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Describes how to create, use, and sort hash tables in Windows PowerShell.<\/p>\n<p style=\"padding-left: 30px\">about_preference_variables&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HelpFile &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Variables that customize the behavior of Windows PowerShell<\/p>\n<p style=\"padding-left: 30px\">about_remote_output&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HelpFile &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Describes how to interpret and format the output of remote commands.<\/p>\n<p style=\"padding-left: 30px\">about_script_internationalization HelpFile Describes the script internationalization features of Windows PowerShell&#8230;<\/p>\n<p style=\"padding-left: 30px\">about_Variables &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HelpFile &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Describes how variables store values that can be used in Windows<\/p>\n<p style=\"padding-left: 30px\">about_Windows_PowerShell_2.0&nbsp;&nbsp; HelpFile &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Describes the new features that are included in Windows PowerShell 2.0.<\/p>\n<p>One reason for the three different permutations of <i>hash table<\/i> is that the term <i>hashtable<\/i> appears in a few parameter names. The other articles always refer to <i>hash table <\/i>as two words. The one instance of <i>hash-table <\/i>in the <b>Get-Winevent<\/b> article is a bug.<\/p>\n<p>JB, first I would like to play around with the <b>Group-Object<\/b> cmdlet. It is cool. The <b>Group-Object<\/b> cmdlet has an <i>ashashtable<\/i> switched parameter that causes the cmdlet to return a hash table. I like to use this parameter, and store the resulting hash table in a variable. In the following command, I use <b>dir<\/b> (an alias for the <b>Get-ChildItem<\/b> cmdlet) to produce a listing of the <b>hsgtest<\/b> directory. The <b>recurse<\/b> switch tells the cmdlet to continue retrieving information from nested directories. I pass the returned objects via the pipeline to the <b>select<\/b> command (<b>select<\/b> is an alias for the <b>Select-Object<\/b> cmdlet). I then pipe the custom object (the object only contains two properties: <b>name<\/b> and <b>fullname<\/b>) to the <b>Group-Object<\/b> cmdlet where the results are grouped on the <b>name<\/b> property and returned as a hash table. The hash table is stored in the <b>$a<\/b> variable. The command to obtain a directory listing, choose the <b>name<\/b> and <b>fullname<\/b> properties, group on the <b>name<\/b> property, and return a hash table is shown here:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\hsgTest&gt; $a = dir -Recurse | select name, fullname | Group-Object -Property name &ndash;AsHashTable<\/p>\n<p>After I have a hash table stored in the <b>$a<\/b> variable, I can look at the keys or the values. First I use the keys property to examine the keys stored in the $a variable. The command and associated output appear here:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\hsgTest&gt; $a.Keys<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">testfile30.txt<\/p>\n<p style=\"padding-left: 30px\">testfile27.txt<\/p>\n<p style=\"padding-left: 30px\">testfile21.txt<\/p>\n<p style=\"padding-left: 30px\">testfile20.txt<\/p>\n<p style=\"padding-left: 30px\">testfile25.txt<\/p>\n<p style=\"padding-left: 30px\">testfile10.txt<\/p>\n<p style=\"padding-left: 30px\">&lt;output is truncated to save space&gt;<\/p>\n<p>Now, I want to see the values that are stored in the $a variable. This is where things begin to get interesting. The command and associated output appear here in truncated fashion.<\/p>\n<p>PS C:\\hsgTest&gt; $a.Values<\/p>\n<p style=\"padding-left: 30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FullName<\/p>\n<p style=\"padding-left: 30px\">&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8211;<\/p>\n<p style=\"padding-left: 30px\">testfile30.txt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C:\\hsgTest\\testfile30.txt<\/p>\n<p style=\"padding-left: 30px\">testfile30.txt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C:\\hsgTest\\hsgtest2\\testfile30.txt<\/p>\n<p style=\"padding-left: 30px\">testfile30.txt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C:\\hsgTest\\hsgtest2\\hsgTest3\\testfile30.txt<\/p>\n<p style=\"padding-left: 30px\">testfile27.txt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C:\\hsgTest\\hsgtest2\\testfile27.txt<\/p>\n<p style=\"padding-left: 30px\">testfile21.txt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C:\\hsgTest\\hsgtest2\\testfile21.txt<\/p>\n<p style=\"padding-left: 30px\">testfile20.txt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C:\\hsgTest\\testfile20.txt<\/p>\n<p style=\"padding-left: 30px\">testfile20.txt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C:\\hsgTest\\hsgtest2\\testfile20.txt<\/p>\n<p style=\"padding-left: 30px\">&lt;output is truncated to save space&gt;<\/p>\n<p>The output above is a bit unexpected because it looks like once again the key and the values are appearing.<\/p>\n<p>In addition, it looks like there are duplicate values for the key. The output of the hash table itself, however, includes grouping information that makes it clear that duplicates are not stored in the $a variable.<\/p>\n<p>PS C:\\hsgTest&gt; $a<\/p>\n<p>&nbsp;<\/p>\n<p>Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Value<\/p>\n<p>&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8211;<\/p>\n<p>testfile30.txt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {@{Name=testfile30.txt; FullName=C:\\hsgTest\\testfile30.txt}, @{Name=testfile30.txt; F&#8230;<\/p>\n<p>testfile27.txt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {@{Name=testfile27.txt; FullName=C:\\hsgTest\\hsgtest2\\testfile27.txt}}<\/p>\n<p>testfile21.txt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {@{Name=testfile21.txt; FullName=C:\\hsgTest\\hsgtest2\\testfile21.txt}}<\/p>\n<p>testfile20.txt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {@{Name=testfile20.txt; FullName=C:\\hsgTest\\testfile20.txt}, @{Name=testfile20.txt; F&#8230;<\/p>\n<p>&lt;output truncated to&nbsp; save space&gt;<\/p>\n<p>A&nbsp;closer look reveals that we have a more complex object stored in the <i>values<\/i> property. To take this closer look I can use the <i>item<\/i> method to retrieve a specific entry from the hash table. The following command shows the information stored in the <i>value <\/i>portion of the hash table.I can use the <i>item<\/i> method to retrieve a specific entry from the hash table. The following command shows the information stored in the <i>value <\/i>portion of the hash table.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\hsgTest&gt; $a.Item(&#8220;testfile30.txt&#8221;)<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FullName<\/p>\n<p style=\"padding-left: 30px\">&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8211;<\/p>\n<p style=\"padding-left: 30px\">testfile30.txt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C:\\hsgTest\\testfile30.txt<\/p>\n<p style=\"padding-left: 30px\">testfile30.txt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C:\\hsgTest\\hsgtest2\\testfile30.txt<\/p>\n<p style=\"padding-left: 30px\">testfile30.txt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C:\\hsgTest\\hsgtest2\\hsgTest3\\testfile30.txt<\/p>\n<p>When I use the <b>item<\/b> method to retrieve information about the <b>testfile30.txt<\/b> key, three items are stored in the value. To see only one of those items, I can <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/06\/19\/top-ten-favorite-powershell-tricks-part-2.aspx\">index into it by using a square bracket and index number<\/a> (you may recall this is <a href=\"http:\/\/blogs.technet.com\/search\/searchresults.aspx?q=top%20ten%20tricks&amp;sections=7618\">one of my top ten favorite Windows PowerShell tricks<\/a>). The code to do this is shown here along with the associated output:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\hsgTest&gt; $a.Item(&#8220;testfile30.txt&#8221;)[0]&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FullName<\/p>\n<p style=\"padding-left: 30px\">&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8211;<\/p>\n<p style=\"padding-left: 30px\">testfile30.txt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C:\\hsgTest\\testfile30.txt<\/p>\n<p>When I address a single item, I can directly access the properties I chose via the <b>Select-Object<\/b> cmdlet. In the following code, I access the <b>name<\/b> property, and then I access the <b>fullname<\/b> property:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\hsgTest&gt; $a.Item(&#8220;testfile30.txt&#8221;)[0].name<\/p>\n<p style=\"padding-left: 30px\">testfile30.txt<\/p>\n<p style=\"padding-left: 30px\">PS C:\\hsgTest&gt; $a.Item(&#8220;testfile30.txt&#8221;)[0].fullname<\/p>\n<p style=\"padding-left: 30px\">C:\\hsgTest\\testfile30.txt<\/p>\n<p>Because I can store lots of different types of things in a hash table (even other hash tables), I do not need to create a custom object via the <b>Select-Object<\/b> cmdlet. I can, in fact, store an entire <b>fileinfo<\/b> or <b>directoryinfo<\/b> object in the hash table. This is illustrated here:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\hsgTest&gt; $b = dir -Recurse | Group-Object -Property name -AsHashTable<\/p>\n<p style=\"padding-left: 30px\">PS C:\\hsgTest&gt; $b.Item(&#8220;testfile30.txt&#8221;)&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; Directory: C:\\hsgTest&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"><span style=\"text-decoration: underline\">Mode<\/span>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">LastWriteTime<\/span>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">Length Name<\/span><\/p>\n<p style=\"padding-left: 30px\">-a&#8212;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7\/1\/2011&nbsp;&nbsp; 8:53 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 testfile30.txt&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; Directory: C:\\hsgTest\\hsgtest2&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"><span style=\"text-decoration: underline\">Mode<\/span>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">LastWriteTime<\/span>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">Length Name<\/span><\/p>\n<p style=\"padding-left: 30px\">-a&#8212;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7\/1\/2011&nbsp;&nbsp; 8:53 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 testfile30.txt&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; Directory: C:\\hsgTest\\hsgtest2\\hsgTest3&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"><span style=\"text-decoration: underline\">Mode<\/span>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">LastWriteTime<\/span>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">Length Name<\/span><\/p>\n<p style=\"padding-left: 30px\">-a&#8212;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7\/1\/2011&nbsp;&nbsp; 8:53 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 testfile30.txt&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">PS C:\\hsgTest&gt; $b.Item(&#8220;testfile30.txt&#8221;)[0]&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; Directory: C:\\hsgTest&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"><span style=\"text-decoration: underline\">Mode<\/span>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">LastWriteTime<\/span>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">Length Name<\/span><\/p>\n<p style=\"padding-left: 30px\">-a&#8212;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7\/1\/2011&nbsp;&nbsp; 8:53 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 testfile30.txt<\/p>\n<p>Any of the properties associated with a <b>fileinfo<\/b> object are now accessible. In the following code, I retrieve the <b>lastwritetime<\/b> property from the file:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\hsgTest&gt; $b.Item(&#8220;testfile30.txt&#8221;)[0].LastWriteTime&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Friday, July 01, 2011 8:53:46 PM<\/p>\n<p>The <b>Get-WinEvent<\/b> cmdlet can use a hash table for a filter. For an excellent article on that technique, see <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/01\/24\/use-powershell-cmdlet-to-filter-event-log-for-easy-parsing.aspx\">Use PowerShell Cmdlet to Filter Event Log for Easy Parsing<\/a>.<\/p>\n<p>The <b>Format-Table<\/b> cmdlet accepts a hash table to create customized output. The hash table takes the place of a single property, and consists of two key\/value pairs. The first key is <b>label<\/b><i> <\/i>and the second key is <b>expression<\/b><i>.<\/i> The <b>expression<\/b><i> <\/i>key accepts a script block. The semicolon separates the two key\/value pairs. The ampersand, opening brace, and closing brace (<b>@{}<\/b>) delineate a hash table. The script block value for the <b>expression<\/b> key also uses a pair of braces to delineate the script block.<\/p>\n<p>In the following code, <b>dir<\/b> (an alias for the <b>Get-ChildItem<\/b> cmdlet) returns a directory listing. The resulting <b>directoryinfo<\/b> and <b>fileinfo<\/b> objects are piped to the <b>Where-Object<\/b> cmdlet (the <b>?<\/b> is an alias for the <b>Where-Object<\/b> cmdlet). The <b>mode<\/b> property is inspected and only objects that do not have a mode that begins with &ldquo;d&rdquo; (a mode of &ldquo;d&#8212;-&ldquo; is a directory) are passed to the <b>Format-Table<\/b> cmdlet (<b>ft<\/b> is an alias for the <b>Format-Table<\/b> cmdlet). The <b>name<\/b> property from the <b>fileinfo<\/b> object is selected, and a custom label called <b>last written<\/b> is added to the table. The <b>last written<\/b> property will display the <b>lastwritetime<\/b> property from the <b>fileinfo<\/b> object. The code is shown here:<\/p>\n<p style=\"padding-left: 30px\">dir | ? { $_.mode -notmatch &#8216;^d&#8217; } | ft name, @{Label=&#8221;last written&#8221; ; Expression = {$_.LastWriteTime}}<\/p>\n<p>The command and associated output are shown in the following figure.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1884.hsg-7-7-11-1.png\"><img decoding=\"async\" style=\"border: 0px\" title=\"Image of command and associated output\" alt=\"Image of command and associated output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1884.hsg-7-7-11-1.png\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>JB, that is all there is to using hash tables inside Windows PowerShell commands. This also ends Hash Table Week. Join me tomorrow when I will talk about playing around with the day of the year. Sound boring? It is not&mdash;trust me. See you tomorrow.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to Use Windows PowerShell hash tables with your cmdlets to create powerful commands. &nbsp; Hey, Scripting Guy! I think I understand hash tables after having read your earlier articles about working with hash tables. What I do not understand is how hash tables work within Windows PowerShell commands. In addition, how do [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[18,51,3,4,45],"class_list":["post-13401","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-arrays-hash-tables-and-dictionary-objects","tag-getting-started","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to Use Windows PowerShell hash tables with your cmdlets to create powerful commands. &nbsp; Hey, Scripting Guy! I think I understand hash tables after having read your earlier articles about working with hash tables. What I do not understand is how hash tables work within Windows PowerShell commands. In addition, how do [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/13401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=13401"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/13401\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=13401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=13401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=13401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}