{"id":1252,"date":"2013-04-09T09:20:15","date_gmt":"2013-04-09T13:20:15","guid":{"rendered":"http:\/\/enterpriseadmins.org\/blog\/?p=1252"},"modified":"2013-04-08T09:13:01","modified_gmt":"2013-04-08T13:13:01","slug":"hashtables-adding-updating-and-removing-items","status":"publish","type":"post","link":"https:\/\/enterpriseadmins.org\/blog\/scripting\/hashtables-adding-updating-and-removing-items\/","title":{"rendered":"Hashtables: Adding, Updating and Removing Items"},"content":{"rendered":"<p>To help describe these concepts, I have listed a few examples based on <a title=\"HTML Color Codes\" href=\"http:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2013\/04\/ColorCodes.csv\" target=\"_blank\">a CSV file containing HTML color codes<\/a>.<\/p>\n<p>For purposes of sample data, create an array object of colors and HTML color codes.<\/p>\n<pre><code class=\"language-powershell\">$colorCodes = Import-Csv ColorCodes.csv<\/code><\/pre>\n<p>Define a hashtable object:<\/p>\n<pre><code class=\"language-powershell\">$colorCodeHT = @{}<\/code><\/pre>\n<p>Examples for adding to a hashtable:<\/p>\n<pre><code class=\"language-powershell\">\r\n# For the old vbscripter (this is the method I use)\r\n# $colorCodeHT.Add('key','value')\r\n$colorCodes | %{$colorCodeHT.Add($_.ColorName, $_.Code)}\r\n\r\n# For the person who likes equal signs\r\n# $colorCodeHT['key'] = 'Value'\r\n$colorCodes | %{$colorCodeHT[$_.ColorName] = $_.Code}\r\n<\/code><\/pre>\n<p>Examples for updating existing entries<\/p>\n<pre><code class=\"language-powershell\">\r\n# Using square brackets, just like the above 'add' example\r\n$colorCodeHT['Red'] = '#123456'\r\n<\/code><\/pre>\n<p>Examples for removing from a hashtable:<\/p>\n<pre><code class=\"language-1\">\r\n# Remove a single item by key\r\n$colorCodeHT.Remove('Red')\r\n\r\n# Remove all of the entries from the hashtable:\r\n$colorCodeHT.Clear()\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>To help describe these concepts, I have listed a few examples based on a CSV file containing HTML color codes. For purposes of sample data, create an array object of colors and HTML color codes. $colorCodes = Import-Csv ColorCodes.csv Define &hellip; <a href=\"https:\/\/enterpriseadmins.org\/blog\/scripting\/hashtables-adding-updating-and-removing-items\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1252","post","type-post","status-publish","format-standard","hentry","category-scripting"],"_links":{"self":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/comments?post=1252"}],"version-history":[{"count":7,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1252\/revisions"}],"predecessor-version":[{"id":1264,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1252\/revisions\/1264"}],"wp:attachment":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/media?parent=1252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/categories?post=1252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/tags?post=1252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}