{"id":633,"date":"2010-04-30T09:43:32","date_gmt":"2010-04-30T14:43:32","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/2010\/04\/bool-vs-switch\/"},"modified":"2010-04-30T09:43:32","modified_gmt":"2010-04-30T14:43:32","slug":"bool-vs-switch","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/scripting\/633\/bool-vs-switch\/","title":{"rendered":"Bool vs Switch"},"content":{"rendered":"<p>I have to say I\u2019m generally impressed with the quality of submissions to this year\u2019s Scripting Games. But there is a recurring concept that some people are using and I think there\u2019s a better way. Some contestants are defining function or script parameters as booleans. But I believe they really should be using the [switch] type. Let me show you why.<\/p>\n<p> <!--more-->  <\/p>\n<p>Very often, a function has a parameter, that if true generally means do X.&#160; Here\u2019s a simple example.<\/p>\n<\/p>\n<pre class=\"PowerShellColorizedScript\"><span style=\"color: #00008b\">Function<\/span> <span style=\"color: #8a2be2\">Test-Bool<\/span> <span style=\"color: #000000\">{<\/span>            \n    <span style=\"color: #00008b\">Param<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #008080\">[string]<\/span><span style=\"color: #ff4500\">$r<\/span><span style=\"color: #a9a9a9\">=<\/span><span style=\"color: #800080\">1<\/span><span style=\"color: #a9a9a9\">,<\/span><span style=\"color: #008080\">[bool]<\/span><span style=\"color: #ff4500\">$log<\/span><span style=\"color: #000000\">)<\/span>            \n            \n    <span style=\"color: #ff4500\">$pi<\/span><span style=\"color: #a9a9a9\">=<\/span><span style=\"color: #008080\">[math]<\/span><span style=\"color: #a9a9a9\">::<\/span><span style=\"color: #000000\">pi<\/span>            \n    <span style=\"color: #ff4500\">$area<\/span><span style=\"color: #a9a9a9\">=<\/span><span style=\"color: #ff4500\">$pi<\/span> <span style=\"color: #a9a9a9\">*<\/span> <span style=\"color: #000000\">(<\/span><span style=\"color: #ff4500\">$r<\/span><span style=\"color: #a9a9a9\">*<\/span><span style=\"color: #ff4500\">$r<\/span><span style=\"color: #000000\">)<\/span>            \n    <span style=\"color: #ff4500\">$msg<\/span><span style=\"color: #a9a9a9\">=<\/span><span style=\"color: #8b0000\">&quot;A circle with a radius of $r has an area of $area&quot;<\/span>            \n    <span style=\"color: #00008b\">if<\/span> <span style=\"color: #000000\">(<\/span><span style=\"color: #ff4500\">$log<\/span><span style=\"color: #000000\">)<\/span> <span style=\"color: #000000\">{<\/span>            \n        <span style=\"color: #ff4500\">$msg<\/span> <span style=\"color: #a9a9a9\">|<\/span> <span style=\"color: #0000ff\">Tee-object<\/span> <span style=\"color: #000080\">-filepath<\/span> <span style=\"color: #8a2be2\">$env:temp\\log.txt<\/span>            \n        <span style=\"color: #0000ff\">write-host<\/span> <span style=\"color: #8b0000\">&quot;Results Logged&quot;<\/span> <span style=\"color: #000080\">-ForegroundColor<\/span> <span style=\"color: #8a2be2\">Green<\/span>            \n    <span style=\"color: #000000\">}<\/span>            \n    <span style=\"color: #00008b\">else<\/span> <span style=\"color: #000000\">{<\/span>            \n        <span style=\"color: #ff4500\">$msg<\/span>            \n    <span style=\"color: #000000\">}<\/span>            \n<span style=\"color: #000000\">}<\/span> <span style=\"color: #006400\">#end function<\/span><\/pre>\n<\/p>\n<p>When the function is run, the intent is that \u2013log should indicate to record the result. If you don\u2019t specify \u2013log, the script runs just fine. But if you want to use \u2013log and indicate that yes, you do want a log, you need to explicitly provide a boolean value<\/p>\n<p>PS C:\\&gt; Test-Bool \u2013r 3 \u2013log:$True<\/p>\n<p>Here are some examples:<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/04\/testbool.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto\" title=\"test-bool\" border=\"0\" alt=\"test-bool\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/04\/testbool_thumb.png\" width=\"484\" height=\"192\" \/><\/a> <\/p>\n<p>Yes, technically it works but it feels clumsy in my opinion. Here\u2019s the same function rewritten using [switch].<\/p>\n<\/p>\n<pre class=\"PowerShellColorizedScript\"><span style=\"color: #00008b\">Function<\/span> <span style=\"color: #8a2be2\">Test-Switch<\/span> <span style=\"color: #000000\">{<\/span>            \n  <span style=\"color: #00008b\">Param<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #008080\">[string]<\/span><span style=\"color: #ff4500\">$r<\/span><span style=\"color: #a9a9a9\">=<\/span><span style=\"color: #800080\">1<\/span><span style=\"color: #a9a9a9\">,<\/span><span style=\"color: #008080\">[switch]<\/span><span style=\"color: #ff4500\">$log<\/span><span style=\"color: #000000\">)<\/span>            \n            \n    <span style=\"color: #ff4500\">$pi<\/span><span style=\"color: #a9a9a9\">=<\/span><span style=\"color: #008080\">[math]<\/span><span style=\"color: #a9a9a9\">::<\/span><span style=\"color: #000000\">pi<\/span>            \n    <span style=\"color: #ff4500\">$area<\/span><span style=\"color: #a9a9a9\">=<\/span><span style=\"color: #ff4500\">$pi<\/span> <span style=\"color: #a9a9a9\">*<\/span> <span style=\"color: #000000\">(<\/span><span style=\"color: #ff4500\">$r<\/span><span style=\"color: #a9a9a9\">*<\/span><span style=\"color: #ff4500\">$r<\/span><span style=\"color: #000000\">)<\/span>            \n    <span style=\"color: #ff4500\">$msg<\/span><span style=\"color: #a9a9a9\">=<\/span><span style=\"color: #8b0000\">&quot;A circle with a radius of $r has an area of $area&quot;<\/span>            \n    <span style=\"color: #00008b\">if<\/span> <span style=\"color: #000000\">(<\/span><span style=\"color: #ff4500\">$log<\/span><span style=\"color: #000000\">)<\/span> <span style=\"color: #000000\">{<\/span>            \n        <span style=\"color: #ff4500\">$msg<\/span> <span style=\"color: #a9a9a9\">|<\/span> <span style=\"color: #0000ff\">Tee-object<\/span> <span style=\"color: #000080\">-filepath<\/span> <span style=\"color: #8a2be2\">$env:temp\\log.txt<\/span>            \n        <span style=\"color: #0000ff\">write-host<\/span> <span style=\"color: #8b0000\">&quot;Results Logged&quot;<\/span> <span style=\"color: #000080\">-ForegroundColor<\/span> <span style=\"color: #8a2be2\">Green<\/span>            \n    <span style=\"color: #000000\">}<\/span>            \n    <span style=\"color: #00008b\">else<\/span> <span style=\"color: #000000\">{<\/span>            \n        <span style=\"color: #ff4500\">$msg<\/span>            \n    <span style=\"color: #000000\">}<\/span>            \n            \n<span style=\"color: #000000\">}<\/span><\/pre>\n<p>When used this way, if the parameter has been specified, the effect is the same as specifying $True.<\/p>\n<p>PS C:\\&gt; Test-Switch \u2013r 4 -log<\/p>\n<p>&#160;<a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/04\/testswitch.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto\" title=\"test-switch\" border=\"0\" alt=\"test-switch\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/04\/testswitch_thumb.png\" width=\"484\" height=\"192\" \/><\/a> <\/p>\n<p>Does this make sense? For those of you who have used [bool] as a parameter type is this more of what you had in mind?&#160; Using [switch] seems cleaner and simpler to me. I was trying to come up with a good example of where [bool] makes sense, but I can\u2019t come up one. If you have a use case, please share.&#160; <\/p>\n<p>Using [bool] within a script or function is a different matter. I\u2019m merely focusing on the type when used to define a parameter.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have to say I\u2019m generally impressed with the quality of submissions to this year\u2019s Scripting Games. But there is a recurring concept that some people are using and I think there\u2019s a better way. Some contestants are defining function or script parameters as booleans. But I believe they really should be using the [switch]&#8230;<\/p>\n","protected":false},"author":1,"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,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[60,75,8],"tags":[32,93,534,189],"class_list":["post-633","post","type-post","status-publish","format-standard","hentry","category-best-practices","category-powershell-v2-0","category-scripting","tag-functions","tag-parameters","tag-powershell","tag-switch"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Bool vs Switch &#8226; The Lonely Administrator<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/scripting\/633\/bool-vs-switch\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Bool vs Switch &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"I have to say I\u2019m generally impressed with the quality of submissions to this year\u2019s Scripting Games. But there is a recurring concept that some people are using and I think there\u2019s a better way. Some contestants are defining function or script parameters as booleans. But I believe they really should be using the [switch]...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/scripting\/633\/bool-vs-switch\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2010-04-30T14:43:32+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/04\/testbool_thumb.png\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/633\\\/bool-vs-switch\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/633\\\/bool-vs-switch\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Bool vs Switch\",\"datePublished\":\"2010-04-30T14:43:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/633\\\/bool-vs-switch\\\/\"},\"wordCount\":278,\"commentCount\":4,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/633\\\/bool-vs-switch\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2010\\\/04\\\/testbool_thumb.png\",\"keywords\":[\"functions\",\"parameters\",\"PowerShell\",\"switch\"],\"articleSection\":[\"Best Practices\",\"PowerShell v2.0\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/633\\\/bool-vs-switch\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/633\\\/bool-vs-switch\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/633\\\/bool-vs-switch\\\/\",\"name\":\"Bool vs Switch &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/633\\\/bool-vs-switch\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/633\\\/bool-vs-switch\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2010\\\/04\\\/testbool_thumb.png\",\"datePublished\":\"2010-04-30T14:43:32+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/633\\\/bool-vs-switch\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/633\\\/bool-vs-switch\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/633\\\/bool-vs-switch\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2010\\\/04\\\/testbool_thumb.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2010\\\/04\\\/testbool_thumb.png\",\"width\":\"484\",\"height\":\"192\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/633\\\/bool-vs-switch\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Best Practices\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/best-practices\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bool vs Switch\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Bool vs Switch &#8226; The Lonely Administrator","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jdhitsolutions.com\/blog\/scripting\/633\/bool-vs-switch\/","og_locale":"en_US","og_type":"article","og_title":"Bool vs Switch &#8226; The Lonely Administrator","og_description":"I have to say I\u2019m generally impressed with the quality of submissions to this year\u2019s Scripting Games. But there is a recurring concept that some people are using and I think there\u2019s a better way. Some contestants are defining function or script parameters as booleans. But I believe they really should be using the [switch]...","og_url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/633\/bool-vs-switch\/","og_site_name":"The Lonely Administrator","article_published_time":"2010-04-30T14:43:32+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/04\/testbool_thumb.png","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/633\/bool-vs-switch\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/633\/bool-vs-switch\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Bool vs Switch","datePublished":"2010-04-30T14:43:32+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/633\/bool-vs-switch\/"},"wordCount":278,"commentCount":4,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/633\/bool-vs-switch\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/04\/testbool_thumb.png","keywords":["functions","parameters","PowerShell","switch"],"articleSection":["Best Practices","PowerShell v2.0","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/633\/bool-vs-switch\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/633\/bool-vs-switch\/","url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/633\/bool-vs-switch\/","name":"Bool vs Switch &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/633\/bool-vs-switch\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/633\/bool-vs-switch\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/04\/testbool_thumb.png","datePublished":"2010-04-30T14:43:32+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/633\/bool-vs-switch\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/633\/bool-vs-switch\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/633\/bool-vs-switch\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/04\/testbool_thumb.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/04\/testbool_thumb.png","width":"484","height":"192"},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/633\/bool-vs-switch\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Best Practices","item":"https:\/\/jdhitsolutions.com\/blog\/category\/best-practices\/"},{"@type":"ListItem","position":2,"name":"Bool vs Switch"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":7992,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7992\/answering-the-cim-directory-challenge\/","url_meta":{"origin":633,"position":0},"title":"Answering the CIM Directory Challenge","author":"Jeffery Hicks","date":"January 8, 2021","format":false,"excerpt":"The last Iron Scripter challenge of 2020 was a big one. If you didn't get a chance to work on it, see what you can come up with then come back to see my approach. As with many of the challenges, the goal isn't to produce a production-ready PowerShell tool,\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/01\/win32_directory.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/01\/win32_directory.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/01\/win32_directory.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/01\/win32_directory.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/01\/win32_directory.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/01\/win32_directory.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":8059,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8059\/solving-the-powershell-conversion-challenge\/","url_meta":{"origin":633,"position":1},"title":"Solving the PowerShell Conversion Challenge","author":"Jeffery Hicks","date":"January 19, 2021","format":false,"excerpt":"Today let's look at how I approached the first Iron Scripter PowerShell challenge of the year. The goal of the challenge was to convert or translate an object into a PowerShell class definition. If you are new to these challenges, the journey to how you achieve the goal is more\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/01\/psobject.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/01\/psobject.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/01\/psobject.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/01\/psobject.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/01\/psobject.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/01\/psobject.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":3990,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3990\/friday-fun-creating-powershell-scripts-with-powershell\/","url_meta":{"origin":633,"position":2},"title":"Friday Fun: Creating PowerShell Scripts with PowerShell","author":"Jeffery Hicks","date":"September 5, 2014","format":false,"excerpt":"Sometimes PowerShell really does seem like magic. Especially when you can use it to handle complicated or tedious tasks, such as creating a PowerShell script. I know many an IT Pro who want to script but without having to actually write a script. Well, I'm not sure that is realistic,\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"012914_1704_CreatingCIM1.png","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/012914_1704_CreatingCIM1-150x150.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":7881,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7881\/answering-the-powershell-registered-user-challenge\/","url_meta":{"origin":633,"position":3},"title":"Answering the PowerShell Registered User Challenge","author":"Jeffery Hicks","date":"November 16, 2020","format":false,"excerpt":"A few weeks ago, an Iron Scripter PowerShell challenge was issued. This was a beginner to intermediate level challenge to get and set the registered user and\/or organization values. These challenges, and solutions such as mine, aren't intended to production-ready tools. Instead, you should use them as learning vehicles to\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":4268,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4268\/friday-fun-size-me-up\/","url_meta":{"origin":633,"position":4},"title":"Friday Fun: Size Me Up","author":"Jeffery Hicks","date":"March 6, 2015","format":false,"excerpt":"Part of day job involves creating training material, often in the form of video training for Pluralsight or articles for Petri.com. Since I usually am covering PowerShell I often need to capture a PowerShell session. And sometimes I want the screen to be a particular size. So over time I've\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":531,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/531\/think-objectively\/","url_meta":{"origin":633,"position":5},"title":"Think Objectively","author":"Jeffery Hicks","date":"December 14, 2009","format":false,"excerpt":"A challenge many new comers to PowerShell face, especially those arriving with a VBScript background, and one that I often talk about, is shifting gears from working with text to working with objects. Here\u2019s a good example. The Win32_OperatingSystem class returns a value for TotalVisibleMemorySize, which should be the amount\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/633","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=633"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/633\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}