{"id":1847,"date":"2014-04-01T23:37:17","date_gmt":"2014-04-01T21:37:17","guid":{"rendered":"http:\/\/michlstechblog.info\/blog\/?p=1847"},"modified":"2014-04-05T22:58:27","modified_gmt":"2014-04-05T20:58:27","slug":"powershell-a-text-based-menu","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/powershell-a-text-based-menu\/","title":{"rendered":"Powershell: A text based menu"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_1847 social_share_privacy clearfix 1.6.4 locale-en_US sprite-en_US\"><\/div><div class=\"twoclick-js\"><script type=\"text\/javascript\">\/* <![CDATA[ *\/\njQuery(document).ready(function($){if($('.twoclick_social_bookmarks_post_1847')){$('.twoclick_social_bookmarks_post_1847').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"Powershell%3A%20A%20text%20based%20menu\",\"the_excerpt\":\"Hi%2C%0D%0A%0D%0Aa%20long%20time%20ago%20I%20wrote%20a%20Menu%20function%20for%20quickly%20choose%20predefined%20options%20in%20a%20script.%20An%20example%0D%0A%0D%0ASource%20the%20menu.ps1%20in%20your%20script%20and%20call%C2%A0%20fShowMenu.%20This%20will%20show%20the%20menu.%20The%20function%20needs%202%20parameters%3A%0D%0AParameter%201%3A%20The%20menu%20title%20as%20string%0D%0AParameter%202%3A%20A%20hashtable%20with%20the%20Menuentries.%20The%20key%20of%20an%20Menuitem%20is%20returned%20by%20the%20function%20the%20corresponding%20value%20is%20shown%20...\",\"txt_info\":\"2 clicks for more data protection:\\r\\n\\r\\nOnly when you click here, the button will be come active and you can send your recommendation to Flattr. When activating, data are transmitted to third parties. \",\"perma_option\":\"off\"}},\"txt_help\":\"When you activate these fields by clicking, information to Flattr may be transferred abroad, and probably may also stored there.\",\"settings_perma\":\"Enable permanently and accept data transmission. \",\"info_link\":\"http:\\\/\\\/www.heise.de\\\/ct\\\/artikel\\\/2-Klicks-fuer-mehr-Datenschutz-1333879.html\",\"uri\":\"https:\\\/\\\/michlstechblog.info\\\/blog\\\/powershell-a-text-based-menu\\\/\",\"post_id\":1847,\"post_title_referrer_track\":\"Powershell%3A+A+text+based+menu\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p>Hi,<\/p>\n<p>a long time ago I wrote a Menu function for quickly choose predefined options in a script. An example<\/p>\n<p>Source the menu.ps1 in your script and call\u00a0 fShowMenu. This will show the menu. The function needs 2 parameters:<br \/>\nParameter 1: The menu title as string<br \/>\nParameter 2: A hashtable with the Menuentries. The key of an Menuitem is returned by the function the corresponding value is shown at the menu.<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n# Source the file\r\n. .\\menu.ps1\r\n# Call Menu funtion\r\nfShowMenu &quot;Choose your favorite Band&quot; @{&quot;sl&quot;=&quot;Slayer&quot;;&quot;me&quot;=&quot;Metallica&quot;;&quot;ex&quot;=&quot;Exodus&quot;;&quot;an&quot;=&quot;Anthrax&quot;}<\/pre>\n<figure id=\"attachment_1849\" aria-describedby=\"caption-attachment-1849\" style=\"width: 702px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/michlstechblog.info\/blog\/wp-content\/uploads\/2014\/04\/PowershellMenu.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-1849 \" title=\"A text based Powershell Menu\" alt=\"A text based Powershell Menu\" src=\"http:\/\/michlstechblog.info\/blog\/wp-content\/uploads\/2014\/04\/PowershellMenu.png\" width=\"702\" height=\"101\" srcset=\"https:\/\/michlstechblog.info\/blog\/wp-content\/uploads\/2014\/04\/PowershellMenu.png 877w, https:\/\/michlstechblog.info\/blog\/wp-content\/uploads\/2014\/04\/PowershellMenu-300x43.png 300w\" sizes=\"auto, (max-width: 702px) 100vw, 702px\" \/><\/a><figcaption id=\"caption-attachment-1849\" class=\"wp-caption-text\">A text based Powershell Menu<\/figcaption><\/figure>\n<p><!--more--><br \/>\nNow you can navigate through the menu by pressing the up and down arrow keys and the return key to quit the menu or you can select an menu entry directly by pressing the leading number or character of the menu item at the keyboard.<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nPS D:\\&gt; fShowMenu &quot;Choose your favorite Band&quot; @{&quot;sl&quot;=&quot;Slayer&quot;;&quot;me&quot;=&quot;Metallica&quot;;&quot;ex&quot;=&quot;Exodus&quot;;&quot;an&quot;=&quot;Anthrax&quot;}\r\n Choose your favorite Band\r\n  1: Metallica\r\n  2: Exodus\r\n  3: Anthrax\r\n  4: Slayer\r\n  Your choice: 3\r\nan\r\n<\/pre>\n<p>In this example &#8220;3&#8221; selects &#8220;Anthrax&#8221; and the function returns &#8220;an&#8221;.<\/p>\n<p>Up to 90 menu items are possible. This should be enough for the most cases.<\/p>\n<p>Michael<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, a long time ago I wrote a Menu function for quickly choose predefined options in a script. An example Source the menu.ps1 in your script and call\u00a0 fShowMenu. This will show the menu. The function needs 2 parameters: Parameter 1: The menu title as string Parameter 2: A hashtable with the Menuentries. The key &hellip; <a href=\"https:\/\/michlstechblog.info\/blog\/powershell-a-text-based-menu\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Powershell: A text based menu<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[344],"tags":[473,133,474],"class_list":["post-1847","post","type-post","status-publish","format-standard","hentry","category-powershell-scripting","tag-menu","tag-powershell","tag-text-based"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/1847","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/comments?post=1847"}],"version-history":[{"count":12,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/1847\/revisions"}],"predecessor-version":[{"id":6771,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/1847\/revisions\/6771"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=1847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=1847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=1847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}