{"id":1149,"date":"2010-07-16T18:03:07","date_gmt":"2010-07-16T09:03:07","guid":{"rendered":"http:\/\/livedevil.net\/?p=1149"},"modified":"2010-07-16T18:03:07","modified_gmt":"2010-07-16T09:03:07","slug":"powershell-hash-tables-%ed%95%b4%ec%8b%9c-%ed%85%8c%ec%9d%b4%eb%b8%94","status":"publish","type":"post","link":"https:\/\/talsu.net\/?p=1149","title":{"rendered":"Powershell &#8211; Hash Tables (\ud574\uc2dc \ud14c\uc774\ube14)"},"content":{"rendered":"<p>Powershell \uc5d0\uc11c\uc758 Hash Table\uc740 .NET \uc758 System.Collections.Hashtable \ud0c0\uc785\uc774\ub2e4. \ub530\ub77c\uc11c \ub3d9\uc77c\ud55c Property\uc640 Method \ub4e4\uc744 \uac00\uc9c0\uace0 \uc788\ub2e4.<\/p>\n<p>Hash Table\uc740 Key-Value Pair(\uc30d) \uc758 Collection \uc774\ub2e4. Key \uc640 Value \uc30d\uc73c\ub85c \uc788\uc5b4\uc57c \uc785\ub825 \ud560 \uc218 \uc788\ub2e4. Value\ub294 null \uac12\uc774 \uac00\ub2a5 \ud558\uc9c0\ub9cc Keys\ub294 null \uac12\uc774 \ud5c8\uc6a9\ub418\uc9c0 \uc54a\ub294\ub2e4.<\/p>\n<h2>Hash Table \uc0dd\uc131<\/h2>\n<p>Hash Table \uac1c\uccb4\ub294 New-Object cmdlet \ub610\ub294 @{ } \ub85c \uc0dd\uc131 \ud560 \uc218 \uc788\ub2e4.<\/p>\n<p>\ub2e4\uc74c\uc740 \ub3d9\uc77c\ud55c \ub3d9\uc791\uc774\ub2e4.<\/p>\n<pre class=\"lang:ps decode:true\">\n$HashA = New-Object -TypeName System.Collections.Hashtable\n$HashB = @{}\n<\/pre>\n<p>@{ }\uc744 \uc774\uc6a9\ud574 \uc0dd\uc131\uacfc \ud568\uaed8 \ucd08\uae30 \uac12\ub4e4\uc744 \uc785\ub825 \ud560 \uc218 \uc788\ub2e4.<br \/>\n@{&#8220;Key&#8221;=&#8221;Value&#8221;;&#8221;Key&#8221;=&#8221;Value&#8221;} \ud615\uc2dd\uc73c\ub85c \uc785\ub825 \ud55c\ub2e4.<\/p>\n<pre class=\"lang:ps decode:true\">\n# @{\"Key\"=\"Value\";\"Key\"=\"Value\"}\n$Hash = @{\"Alpha\"=1111; \"Bravo\"=2222; \"Charlie\"=3333}\n<\/pre>\n<p>\uc0dd\uc131\ud55c $Hash\ub97c \ud655\uc778 \ud574 \ubcf4\uc790.<\/p>\n<pre class=\"lang:default nums:false decode:true\">\nPS > $Hash\n\nName                           Value\n----                           -----\nCharlie                        3333\nAlpha                          1111\nBravo                          2222\n<\/pre>\n<p>Hash Table \uc758 \ud2b9\uc131\uc0c1 \uc21c\uc11c\ub294 \uc2e0\uacbd \uc4f0\uc9c0 \uc54a\ub294\ub2e4. \ud544\uc694\ud558\uba74 \uc815\ub82c\ud574\uc11c \uc4f0\ub3c4\ub85d \ud558\uc790.<\/p>\n<h2>\uc0ac\uc6a9 \uc608<\/h2>\n<pre class=\"lang:ps decode:true\">\n$Hash = @{\"Alpha\"=1111; \"Bravo\"=2222; \"Charlie\"=3333}\n\n$Hash.Count\t\t\t\t\t# 3\n\n$Hash.Add(\"Delta\", 4444)\t# Element \ucd94\uac00.\n\n$Hash.Count\t\t\t\t\t# 4\n\n$Hash.Add(\"Bravo\", 5555)\t# Error - \uc774\ubbf8 \uc874\uc7ac \ud558\ub294 Key.\n\n$Hash.Remove(\"Bravo\")\t\t# Bravo Key\ub97c \uac00\uc9c4 Element \uc0ad\uc81c.\n\n$Hash.Contains(\"Charlie\")\t# True - Charlie \ub77c\ub294 Key\ub97c \ud3ec\ud568\ud558\uace0 \uc788\ub2e4.\n\n$Hash.Contains(\"Bravo\")\t\t# False - Bravo \ub77c\ub294 Key\ub294 \uc874\uc7ac\ud558\uc9c0 \uc54a\ub294\ub2e4.\n<\/pre>\n<h2>Key, Value\uc758 \uc811\uadfc<\/h2>\n<p>Key\uc5d0 \ud574\ub2f9\ud558\ub294 Value\ub97c \uc5bb\uae30 \uc704\ud574\uc11c\ub294 [ ]\uc5f0\uc0b0\uc790\ub97c \uc774\uc6a9\ud558\uc5ec \uc811\uadfc \ud55c\ub2e4.<\/p>\n<pre class=\"lang:ps nums:false decode:true\">\n$Value = $Hash[\"Key\"]\n<\/pre>\n<p>Powershell \uc5d0\uc11c Hash Table \uac1c\uccb4\ub294 \ud3ec\ud568\ud558\uace0 \uc788\ub294 Key\ub4e4\uc758 Collection\uacfc Value\ub4e4\uc758 Collection\uc744 \uc81c\uacf5 \ud55c\ub2e4.<\/p>\n<h4>.Values\ub97c \uc774\uc6a9\ud558\uc5ec Value\ub4e4\uc744 \uc21c\ud68c<\/h4>\n<pre class=\"lang:ps nums:false decode:true\">\nforeach ($value in $Hash.Values)\n{\n\tWrite-Host $value\n}\n<\/pre>\n<h4>.Keys\ub97c \uc774\uc6a9\ud558\uc5ec key\ub4e4\uc744 \uc21c\ud68c<\/h4>\n<pre class=\"lang:ps nums:false decode:true\">\nforeach ($key in $Hash.Keys)\n{\n\tWrite-Host $key\n}\n<\/pre>\n<h4>.Keys\ub97c \uc774\uc6a9\ud558\uc5ec key\uc640 value\ub97c \uc21c\ud68c<\/h4>\n<pre class=\"lang:ps nums:false decode:true\">\nforeach ($key in $Hash.Keys)\n{\n\tWrite-Host (\"{0} - {1}\" -f $key, $Hash[$key])\n}\n<\/pre>\n<h3>Hash Table \uc21c\ud68c\uc2dc \uc8fc\uc758 \uc0ac\ud56d<\/h3>\n<p>.Net\uacfc \ub2e4\ub974\uac8c Powershell \uc5d0\uc11c\ub294 .Keys \ub098 .Values\ub97c \uc0ac\uc6a9\ud558\uc9c0 \uc54a\uace0 \uc9c1\uc811 HashTable \uac1c\uccb4\uc5d0 \uc21c\ud68c\ub97c \uc2dc\ub3c4 \ud560 \ub54c\uc5d0\ub294 Collection\uc73c\ub85c \uc778\uc2dd\ud558\uc9c0 \uc54a\ub294\ub2e4. foreach \ub610\ub294 pipeline \uc5d0\uc11c HashTable \ud0c0\uc785\uc744 Collection\uc73c\ub85c \ucc29\uac01\ud558\uc9c0 \ub9d0\uc790.<\/p>\n<p>\uc608\ub97c \ub4e4\uc5b4 .NET C# \uc5d0\uc11c\ub294<\/p>\n<pre class=\"lang:c# decode:true\">\nHashtable openWith = new Hashtable();\n\nopenWith.Add(\"txt\", \"notepad.exe\");\nopenWith.Add(\"bmp\", \"paint.exe\");\nopenWith.Add(\"dib\", \"paint.exe\");\nopenWith.Add(\"rtf\", \"wordpad.exe\");\n\nint count = 0;\n\nforeach( DictionaryEntry de in openWith )\n{\n            Console.WriteLine(\"Key = {0}, Value = {1}\", de.Key, de.Value);\n            count++;\n}\n\nConsole.WriteLine(count);            \/\/ 4\n<\/pre>\n<p>foreach\ub85c HashTable\uc744 \uc811\uadfc\ud558\uc5ec DictionaryEntry\uc5d0\uc11c .Key\uc640 .Value\uc5d0 \uc811\uadfc\ud558\uc600\ub2e4.<br \/>\ncount \ubcc0\uc218\ub294 4\ubc88 \uc99d\uac00 \ud558\uc600\ub2e4.<\/p>\n<p>\ud558\uc9c0\ub9cc Powershell \uc5d0\uc11c\ub294<\/p>\n<pre class=\"lang:ps decode:true\">\n$Hash = @{\"Alpha\"=1111; \"Bravo\"=2222; \"Charlie\"=3333}\n\n[int]$counter = 0\n\nforeach ($item in $Hash)\n{\n\tWrite-Host (\"Key = {0}, Value = {1}\" -f $item.Key , $item.Value)\n\t$counter++\n}\n\n$counter            # 1\n<\/pre>\n<p>\ub2e4\uc74c\uacfc \uac19\uc740 \ucd9c\ub825\uc744 \ubcfc \uac83\uc774\ub2e4.<\/p>\n<pre class=\"lang:default nums:false decode:true\">\nKey = , Value =\n1\n<\/pre>\n<p>Key\uc640 Value \uac00 \ube44\uc5b4 \uc788\ub294 \uac83\uc740 .Key .Value \ub9f4\ubc84\uac00 \uc5c6\uae30 \ub54c\ubb38\uc5d0 $null \uc774 \ucd9c\ub825 \ub41c \uac83\uc774\ub2e4. \uc774 \ub9d0\uc740 \uace7 $item \ubcc0\uc218\uac00 DictionaryEntry \ud0c0\uc785\uc774 \uc544\ub2c8\ub77c\ub294 \ub73b\uc774\ub2e4. \uac8c\ub2e4\uac00 count \uac00 \ud55c\ubc88\ub9cc \uc99d\uac00 \ud55c\uac83\uc73c\ub85c \ubcf4\uc544 HashTable \ud0c0\uc785\uc758 \uac1c\uccb4\ub294 Collection\uc73c\ub85c \uc778\uc2dd \ud558\uc9c0 \uc54a\ub294\ub2e4. \uc989 \uc704 \ucf54\ub4dc\uc5d0\uc11c foreach \ub0b4\ubd80\uc758 $item\uc740 HashTable \ud0c0\uc785\uc774\ub2e4.<\/p>\n<p>\ub2e4\uc74c\uacfc \uac19\uc774 \ud655\uc778\ud574\ubcf4\uba74 \ub354\uc6b1 \uba85\ud655\ud558\uac8c \uc774\ud574 \ud560 \uc218 \uc788\ub2e4.<\/p>\n<pre class=\"lang:ps decode:true\">\n$Hash = @{\"Alpha\"=1111; \"Bravo\"=2222; \"Charlie\"=3333}\nforeach ($item in $Hash)\n{\n\t$item.GetType();\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Powershell \uc5d0\uc11c\uc758 Hash Table\uc740 .NET \uc758 System.Collections.Hashtable \ud0c0\uc785\uc774\ub2e4. \ub530\ub77c\uc11c \ub3d9\uc77c\ud55c Property\uc640 Method \ub4e4\uc744 \uac00\uc9c0\uace0 \uc788\ub2e4. Hash Table\uc740 Key-Value Pair(\uc30d) \uc758 Collection \uc774\ub2e4. Key \uc640 Value \uc30d\uc73c\ub85c \uc788\uc5b4\uc57c \uc785\ub825 \ud560 \uc218 \uc788\ub2e4. Value\ub294 null \uac12\uc774 \uac00\ub2a5 \ud558\uc9c0\ub9cc Keys\ub294 null \uac12\uc774 \ud5c8\uc6a9\ub418\uc9c0 \uc54a\ub294\ub2e4. Hash Table \uc0dd\uc131 Hash Table \uac1c\uccb4\ub294 New-Object cmdlet \ub610\ub294 @{ } \ub85c \uc0dd\uc131 \ud560 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[27],"tags":[74,135,136,155,481,249,275,370],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pXV5a-ix","_links":{"self":[{"href":"https:\/\/talsu.net\/index.php?rest_route=\/wp\/v2\/posts\/1149"}],"collection":[{"href":"https:\/\/talsu.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/talsu.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/talsu.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/talsu.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1149"}],"version-history":[{"count":1,"href":"https:\/\/talsu.net\/index.php?rest_route=\/wp\/v2\/posts\/1149\/revisions"}],"predecessor-version":[{"id":2338,"href":"https:\/\/talsu.net\/index.php?rest_route=\/wp\/v2\/posts\/1149\/revisions\/2338"}],"wp:attachment":[{"href":"https:\/\/talsu.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/talsu.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1149"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/talsu.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}