{"id":2741,"date":"2013-10-11T11:59:00","date_gmt":"2013-10-11T11:59:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/10\/11\/powertip-add-key-value-pair-to-ordered-dictionary\/"},"modified":"2013-10-11T11:59:00","modified_gmt":"2013-10-11T11:59:00","slug":"powertip-add-key-value-pair-to-ordered-dictionary","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-add-key-value-pair-to-ordered-dictionary\/","title":{"rendered":"PowerTip: Add Key-Value Pair to Ordered Dictionary"},"content":{"rendered":"<p><strong>Summary<\/strong>: Add a key-value pair to the first position in an ordered dictionary.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\">&nbsp;How can I use Windows PowerShell to add a key-value pair to the first position in an ordered dictionary?<\/p>\n<p style=\"padding-left: 30px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\">Use the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.collections.specialized.ordereddictionary.insert.aspx\">Insert<\/a> method, which takes an index (starting with zero), a key, and a value. <br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; To add <strong>color = blue <\/strong>to the ordered dictionary in the <strong>$od<\/strong> variable:<\/p>\n<p class=\"Code\" style=\"padding-left: 120px\">PS C:&gt; $od<\/p>\n<p class=\"Code\" style=\"padding-left: 120px\">Name&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;Value<\/p>\n<p class=\"Code\" style=\"padding-left: 120px\">&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8211;<\/p>\n<p class=\"Code\" style=\"padding-left: 120px\">shape&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rectangle<\/p>\n<p class=\"Code\" style=\"padding-left: 120px\">distance&nbsp;&nbsp; 50<\/p>\n<p class=\"Code\" style=\"padding-left: 120px\">&nbsp;<\/p>\n<p class=\"Code\" style=\"padding-left: 120px\">PS C:&gt; $od.Insert(0, &#8220;color&#8221;, &#8220;blue&#8221;)<\/p>\n<p class=\"Code\" style=\"padding-left: 120px\">PS C:&gt; $od<\/p>\n<p class=\"Code\" style=\"padding-left: 120px\">&nbsp;<\/p>\n<p class=\"Code\" style=\"padding-left: 120px\">Name&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;Value<\/p>\n<p class=\"Code\" style=\"padding-left: 120px\">&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8211;<\/p>\n<p class=\"Code\" style=\"padding-left: 120px\">color&nbsp; &nbsp;&nbsp;&nbsp; blue<\/p>\n<p class=\"Code\" style=\"padding-left: 120px\">shape&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rectangle<\/p>\n<p class=\"Code\" style=\"padding-left: 120px\">distance&nbsp;&nbsp; 50<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Add a key-value pair to the first position in an ordered dictionary. &nbsp;How can I use Windows PowerShell to add a key-value pair to the first position in an ordered dictionary? Use the Insert method, which takes an index (starting with zero), a key, and a value. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; To add [&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":[370,356,4,45],"class_list":["post-2741","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-june-blender","tag-powertip","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Add a key-value pair to the first position in an ordered dictionary. &nbsp;How can I use Windows PowerShell to add a key-value pair to the first position in an ordered dictionary? Use the Insert method, which takes an index (starting with zero), a key, and a value. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; To add [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2741","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=2741"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2741\/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=2741"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=2741"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=2741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}