{"id":6868,"date":"2019-10-11T11:08:11","date_gmt":"2019-10-11T15:08:11","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=6868"},"modified":"2019-10-11T11:18:08","modified_gmt":"2019-10-11T15:18:08","slug":"understanding-the-powershell-7-ternary-operator","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell-7\/6868\/understanding-the-powershell-7-ternary-operator\/","title":{"rendered":"Understanding the PowerShell 7 Ternary Operator"},"content":{"rendered":"<p>I've been writing about and teaching PowerShell from the very beginning. My focus has always been on making it easier for IT Pro to use PowerShell in their daily work to make life easier and to advance their careers. This focus has undoubtedly been challenging as the language has evolved over the years. With PowerShell 7, that is going to continue. Microsoft is adding many new features to the next version of PowerShell.\u00a0 It seems to me that many of these features are designed to meet Microsoft's needs.\u00a0 One thing that is becoming clearer to me with each new release is that PowerShell is now many things to many people. It is like the proverbial elephant described by a group of blind men; it means something different depending on what you are touching.<\/p>\n<h2>Meet the Ternary Operator<\/h2>\n<p>One of the additions to the latest PowerShell 7 preview is the <em>ternary <\/em>operator. If your background is like mine, you are saying, \"The Whatery?\" According to <a href=\"https:\/\/en.wikipedia.org\/wiki\/Ternary_operation\" target=\"_blank\" rel=\"noopener noreferrer\">Wikipedia<\/a>, this is a well-established computer science term.\u00a0 The operator allows for creating a concise conditional statement.<\/p>\n<pre>&lt;if some condition is true&gt; ? &lt;this&gt;:&lt;else this&gt;<\/pre>\n<p>Using this operator in PowerShell 7 means, you can write a PowerShell expression like this:<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">$IsWindows ? \"ok\":\"not ok\"<\/pre>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/10\/image-6.png\"><img loading=\"lazy\" decoding=\"async\" style=\"margin: 0px; display: inline; background-image: none;\" title=\"image\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/10\/image_thumb-6.png\" alt=\"image\" width=\"761\" height=\"168\" border=\"0\" \/><br \/>\n<\/a><\/p>\n<p>The traditional If statement alternative would be:<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">if ($IsWindows) {\n    \"ok\"\n}\nelse {\n    \"not ok\"\n}\n<\/pre>\n<p>In some regards, the ternary operator is not that complicated to figure out. Although there is one major difference. When using an If statement, the Else clause is completely optional. When using the ternary operator the conditional Else component is required.<\/p>\n<p>Here's a traditional If\/Else statement.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">if ($IsWindows) {\n    Get-CimInstance -ClassName win32_service -filter \"name='bits'\"\n}\nelse {\n    Write-Warning \"This command requires Windows\"\n}\n<\/pre>\n<p>Using the new ternary operator you would write it like this:<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">$IsWindows ? (Get-CimInstance -ClassName win32_service -filter \"name='bits'\") : (Write-Warning \"This command requires Windows\")\n<\/pre>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/10\/image-7.png\"><img loading=\"lazy\" decoding=\"async\" style=\"margin: 0px; display: inline; background-image: none;\" title=\"image\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/10\/image_thumb-7.png\" alt=\"image\" width=\"1028\" height=\"73\" border=\"0\" \/><\/a><\/p>\n<p>The ternary operator appears to be handy for simple conditional statements. Consider this traditional code.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">if ($IsWindows) {\n    Get-CimInstance -ClassName win32_service -filter \"name='bits'\"\n    Get-CimInstance -ClassName win32_service -filter \"name='wsearch'\"\n}\nelse {\n    Clear-Host\n    Get-Date\n    Write-Warning \"This command requires Windows\"\n}\n<\/pre>\n<p>Compared to the ternary operator version.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">$IsWindows ? (Get-CimInstance -ClassName win32_service -filter \"name='bits'\"), (Get-CimInstance -ClassName win32_service -filter \"name='wsearch'\") : (Clear-Host),(Get-Date),(Write-Warning \"This command requires Windows\")\n<\/pre>\n<p>It works but feels a bit clunky to me.<\/p>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/10\/image-8.png\"><img loading=\"lazy\" decoding=\"async\" style=\"margin: 0px; display: inline; background-image: none;\" title=\"image\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/10\/image_thumb-8.png\" alt=\"image\" width=\"1028\" height=\"171\" border=\"0\" \/><\/a><\/p>\n<p>I'll admit this is a bit of a contrived example. And in case you are wondering, from what I've seen there is no performance advantage between using If\/Else or the ternary operatory.<\/p>\n<p>If the goal is succinctness,\u00a0 PowerShell doesn't care about formatting. These two statements have the same result.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">if ($IsLinux) { ls -al } else { Write-Warning \"This command requires Linux\" }\n$isLinux ? (ls -al) : (Write-Warning \"This command requires Linux\")\n<\/pre>\n<p>Which do you prefer?<\/p>\n<h2>What Does This Mean to You?<\/h2>\n<p>I'm not expecting Microsoft to backport this operator to previous versions of PowerShell. Which means you have a dependency on PowerShell 7 if you want to use it. For simple conditional statements at the console, I guess I can see the appeal.<\/p>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/10\/image-9.png\"><img loading=\"lazy\" decoding=\"async\" style=\"margin: 0px; display: inline; background-image: none;\" title=\"image\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/10\/image_thumb-9.png\" alt=\"image\" width=\"1028\" height=\"147\" border=\"0\" \/><\/a><\/p>\n<p>But if you are writing a script file, I don't see any advantage yet. This is a new feature that many people won't understand at first. Personally, something like this is clearer.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">if ((get-date).DayOfWeek -eq \"Friday\") {\n $var = \"tgif\"\n } \n else {\n $var = \"blah\"         \n}\n<\/pre>\n<p>Even if you are new to PowerShell, there's not much mystery about what is happening.<\/p>\n<p>All of this doesn't mean I'm telling you to avoid using this operator. I don't come from a developer background so this operator is not something that I've missed and the traditional If statement works fine for me.<\/p>\n<p>Because I don't have a developer background, if there are compelling use cases for this operator, I'd love to hear about them because I'm betting it will involve something new that I haven't learned yet. For the rest of you with PowerShell 7 preview 4 or later installed, try out the new operator and see where it makes sense for you.<\/p>\n<h3>Update<\/h3>\n<p>Apparently, Adam Bertram and I are on the same page these days. Here's his take published today at Petri.com https:\/\/www.petri.com\/using-the-ternary-conditional-operator-in-powershell-7<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been writing about and teaching PowerShell from the very beginning. My focus has always been on making it easier for IT Pro to use PowerShell in their daily work to make life easier and to advance their careers. This focus has undoubtedly been challenging as the language has evolved over the years. With PowerShell&#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":"Just published: Understanding the #PowerShell 7 Ternary Operator","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[610],"tags":[414,611,540],"class_list":["post-6868","post","type-post","status-publish","format-standard","hentry","category-powershell-7","tag-operators","tag-powershell-7","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Understanding the PowerShell 7 Ternary Operator &#8226; The Lonely Administrator<\/title>\n<meta name=\"description\" content=\"The latest PowerShell 7 preview brings a new operator to the table. What is it and how does it work? What does it mean to you? I have some answers for you.\" \/>\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\/powershell-7\/6868\/understanding-the-powershell-7-ternary-operator\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Understanding the PowerShell 7 Ternary Operator &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"The latest PowerShell 7 preview brings a new operator to the table. What is it and how does it work? What does it mean to you? I have some answers for you.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell-7\/6868\/understanding-the-powershell-7-ternary-operator\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2019-10-11T15:08:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-10-11T15:18:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/10\/image_thumb-6.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=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-7\\\/6868\\\/understanding-the-powershell-7-ternary-operator\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-7\\\/6868\\\/understanding-the-powershell-7-ternary-operator\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Understanding the PowerShell 7 Ternary Operator\",\"datePublished\":\"2019-10-11T15:08:11+00:00\",\"dateModified\":\"2019-10-11T15:18:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-7\\\/6868\\\/understanding-the-powershell-7-ternary-operator\\\/\"},\"wordCount\":583,\"commentCount\":4,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-7\\\/6868\\\/understanding-the-powershell-7-ternary-operator\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/10\\\/image_thumb-6.png\",\"keywords\":[\"operators\",\"PowerShell 7\",\"Scripting\"],\"articleSection\":[\"PowerShell 7\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-7\\\/6868\\\/understanding-the-powershell-7-ternary-operator\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-7\\\/6868\\\/understanding-the-powershell-7-ternary-operator\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-7\\\/6868\\\/understanding-the-powershell-7-ternary-operator\\\/\",\"name\":\"Understanding the PowerShell 7 Ternary Operator &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-7\\\/6868\\\/understanding-the-powershell-7-ternary-operator\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-7\\\/6868\\\/understanding-the-powershell-7-ternary-operator\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/10\\\/image_thumb-6.png\",\"datePublished\":\"2019-10-11T15:08:11+00:00\",\"dateModified\":\"2019-10-11T15:18:08+00:00\",\"description\":\"The latest PowerShell 7 preview brings a new operator to the table. What is it and how does it work? What does it mean to you? I have some answers for you.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-7\\\/6868\\\/understanding-the-powershell-7-ternary-operator\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-7\\\/6868\\\/understanding-the-powershell-7-ternary-operator\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-7\\\/6868\\\/understanding-the-powershell-7-ternary-operator\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/10\\\/image_thumb-6.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/10\\\/image_thumb-6.png\",\"width\":761,\"height\":168},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-7\\\/6868\\\/understanding-the-powershell-7-ternary-operator\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell 7\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell-7\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Understanding the PowerShell 7 Ternary Operator\"}]},{\"@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":"Understanding the PowerShell 7 Ternary Operator &#8226; The Lonely Administrator","description":"The latest PowerShell 7 preview brings a new operator to the table. What is it and how does it work? What does it mean to you? I have some answers for you.","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\/powershell-7\/6868\/understanding-the-powershell-7-ternary-operator\/","og_locale":"en_US","og_type":"article","og_title":"Understanding the PowerShell 7 Ternary Operator &#8226; The Lonely Administrator","og_description":"The latest PowerShell 7 preview brings a new operator to the table. What is it and how does it work? What does it mean to you? I have some answers for you.","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell-7\/6868\/understanding-the-powershell-7-ternary-operator\/","og_site_name":"The Lonely Administrator","article_published_time":"2019-10-11T15:08:11+00:00","article_modified_time":"2019-10-11T15:18:08+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/10\/image_thumb-6.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":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-7\/6868\/understanding-the-powershell-7-ternary-operator\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-7\/6868\/understanding-the-powershell-7-ternary-operator\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Understanding the PowerShell 7 Ternary Operator","datePublished":"2019-10-11T15:08:11+00:00","dateModified":"2019-10-11T15:18:08+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-7\/6868\/understanding-the-powershell-7-ternary-operator\/"},"wordCount":583,"commentCount":4,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-7\/6868\/understanding-the-powershell-7-ternary-operator\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/10\/image_thumb-6.png","keywords":["operators","PowerShell 7","Scripting"],"articleSection":["PowerShell 7"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell-7\/6868\/understanding-the-powershell-7-ternary-operator\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-7\/6868\/understanding-the-powershell-7-ternary-operator\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell-7\/6868\/understanding-the-powershell-7-ternary-operator\/","name":"Understanding the PowerShell 7 Ternary Operator &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-7\/6868\/understanding-the-powershell-7-ternary-operator\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-7\/6868\/understanding-the-powershell-7-ternary-operator\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/10\/image_thumb-6.png","datePublished":"2019-10-11T15:08:11+00:00","dateModified":"2019-10-11T15:18:08+00:00","description":"The latest PowerShell 7 preview brings a new operator to the table. What is it and how does it work? What does it mean to you? I have some answers for you.","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-7\/6868\/understanding-the-powershell-7-ternary-operator\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell-7\/6868\/understanding-the-powershell-7-ternary-operator\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-7\/6868\/understanding-the-powershell-7-ternary-operator\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/10\/image_thumb-6.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/10\/image_thumb-6.png","width":761,"height":168},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-7\/6868\/understanding-the-powershell-7-ternary-operator\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell 7","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-7\/"},{"@type":"ListItem","position":2,"name":"Understanding the PowerShell 7 Ternary Operator"}]},{"@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":8750,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8750\/powershell-plans-for-2022\/","url_meta":{"origin":6868,"position":0},"title":"PowerShell Plans for 2022","author":"Jeffery Hicks","date":"December 27, 2021","format":false,"excerpt":"I'm not much for writing year in review pieces. Nor, to be honest, do I often write New Year's resolutions. But I've been thinking about the work I've done this past year and what I might be doing in 2022 so I thought I'd share some thoughts on what 2022\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"binoculars","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pexels-skitterphoto-63901.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":7661,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7661\/taking-issue-with-powershell\/","url_meta":{"origin":6868,"position":1},"title":"Taking Issue with PowerShell","author":"Jeffery Hicks","date":"August 26, 2020","format":false,"excerpt":"Do you have a moment? I think it's time we had a little chat. No, no...you have done anything wrong. In fact, what I really need is your help. Because you are a member of the global PowerShell community, I felt I could talk to you. You do enjoy being\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\/08\/get-psissue-summary.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/08\/get-psissue-summary.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/08\/get-psissue-summary.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/08\/get-psissue-summary.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/08\/get-psissue-summary.png?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":7992,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7992\/answering-the-cim-directory-challenge\/","url_meta":{"origin":6868,"position":2},"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":8754,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8754\/accelerate-pester-test-development\/","url_meta":{"origin":6868,"position":3},"title":"Accelerate Pester Test Development","author":"Jeffery Hicks","date":"December 28, 2021","format":false,"excerpt":"The other day I shared my PowerShell plans for 2022. And needless to say, I didn't wait to dig in. I am working on a new module and since it won't be published until next month, I went ahead and marked it as Core only. I also started writing a\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\/12\/new-pesterblock.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/new-pesterblock.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/new-pesterblock.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/new-pesterblock.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/new-pesterblock.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/new-pesterblock.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":1806,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1806\/wmi-powershell-tricks-for-windows-server\/","url_meta":{"origin":6868,"position":4},"title":"WMI PowerShell Tricks for Windows Server&#8230;","author":"Jeffery Hicks","date":"November 15, 2011","format":false,"excerpt":"WMI PowerShell Tricks for Windows Server Management*My first article for @petri_co_il on WMI PowerShell Tricks http:\/\/bit.ly\/rx1YrD Get-WMIObject - PowerShell Tricks Windows Server Management Get-WMIObject in Windows Powershell makes it easier to utilize Windows Management Instrumentation (WMI) and makes managing windows servers much easier.","rel":"","context":"In &quot;Google Plus&quot;","block_context":{"text":"Google Plus","link":"https:\/\/jdhitsolutions.com\/blog\/category\/google-plus\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1551,"url":"https:\/\/jdhitsolutions.com\/blog\/wmi\/1551\/find-non-system-service-accounts-with-powershell-and-wmi\/","url_meta":{"origin":6868,"position":5},"title":"Find Non System Service Accounts with PowerShell and WMI","author":"Jeffery Hicks","date":"July 5, 2011","format":false,"excerpt":"As easy as Get-Service is to use in PowerShell, it has one limitation for IT Pros: it can't show you what account the service is running under. In old school terms, \"What is the service account?\" Fortunately you can get that information using WMI. Here's a query you can use\u2026","rel":"","context":"In &quot;PowerShell v2.0&quot;","block_context":{"text":"PowerShell v2.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-v2-0\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/6868","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=6868"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/6868\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=6868"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=6868"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=6868"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}