{"id":1411,"date":"2012-08-26T15:07:11","date_gmt":"2012-08-26T13:07:11","guid":{"rendered":"https:\/\/www.buarotti.ch\/?p=1411"},"modified":"2021-12-26T20:06:17","modified_gmt":"2021-12-26T19:06:17","slug":"powershell-function-if-else-selection-example","status":"publish","type":"post","link":"https:\/\/www.buarotti.ch\/?p=1411","title":{"rendered":"PowerShell Function If Else Selection (Example)"},"content":{"rendered":"\n<pre class=\"wp-block-preformatted\"><\/pre>\n\n\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\n\n## Function PS Read-Host Select Example##\nFunction myfunction\n{\n$path = &quot;yourpath&quot;\n$1 = &quot;1. One&quot;\n$2 = &quot;2. Two&quot;\n$3 = &quot;3. Three&quot;\n$x = &quot;Exit&quot;\n\nwrite-host &quot;$1&quot;\nwrite-host &quot;$2&quot;\nwrite-host &quot;$3&quot;\n$Selection = Read-Host &quot;Please Select (1-3) or Exit (x)&quot;\ncls\n## Selection Handling\nif ($Selection -eq &quot;1&quot;) {\n&quot;you selecting $1&quot;\n$path = &quot;$path\\$1&quot;\n&quot;$path&quot;\n}\nelseif ($Selection -eq &quot;2&quot;) {\n&quot;.... you selecting $2&quot;\n$path = &quot;$path\\$2&quot;\n&quot;$path&quot;\n}\nelseif ($Selection -eq &quot;3&quot;) {\n&quot;.... you selecting $3&quot;\n$path = &quot;$path\\$3&quot;\n&quot;$path&quot;\n}\n## Exit condition\nelseif ($Selection -eq &quot;x&quot;) {\nexit\n}\n## No Valid Selection\nelseif ($Selection -ge $null) {\n&quot;---------------------------------------------------&quot;\nwrite-host &quot; no valid Selection! Please Select again&quot;\n&quot;---------------------------------------------------&quot;\n# myfunction\n}\n}\n## End Function Select ##\n\n## Run Function ##\nmyfunction\n\n<\/pre>\n\n\n<h3>Related Images:<\/h3>","protected":false},"excerpt":{"rendered":"<p>Related Images:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[14],"tags":[],"class_list":["post-1411","post","type-post","status-publish","format-standard","hentry","category-powershell"],"_links":{"self":[{"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=\/wp\/v2\/posts\/1411","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1411"}],"version-history":[{"count":23,"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=\/wp\/v2\/posts\/1411\/revisions"}],"predecessor-version":[{"id":2089,"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=\/wp\/v2\/posts\/1411\/revisions\/2089"}],"wp:attachment":[{"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}