{"id":2175,"date":"2012-04-05T09:24:02","date_gmt":"2012-04-05T13:24:02","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=2175"},"modified":"2012-04-05T09:24:02","modified_gmt":"2012-04-05T13:24:02","slug":"try-and-catch-me-if-you-can","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2175\/try-and-catch-me-if-you-can\/","title":{"rendered":"Try and Catch Me If You Can"},"content":{"rendered":"<p>In looking at entries in this year's Scripting Games, as well as posts I see in PowerShell forums, I thought I'd post a short guide to properly using Try\/Catch. This is the way I think it should be used.  Let's start with a Try\/Catch block that might look ok.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\nTry {<br \/>\n  Get-Service Foo<br \/>\n}<\/p>\n<p>Catch {<br \/>\n  Write-Warning \"Oops\"<br \/>\n  Write-Warning $_.Exception.Message<br \/>\n}<br \/>\n<\/code><\/p>\n<p>You would expect that if the service FOO can't be found that the code in the Catch script block will run.<\/p>\n<p><code lang=\"DOS\"><br \/>\nPS C:\\work> .\\trydemo.ps1<br \/>\nGet-Service : Cannot find any service with service name 'Foo'.<br \/>\nAt C:\\work\\trydemo.ps1:4 char:14<br \/>\n+   Get-Service <<<<  Foo\n    + CategoryInfo          : ObjectNotFound: (Foo:String) [Get-Service], Serv\n   iceCommandException\n    + FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.\n   Commands.GetServiceCommand\n<\/code><\/p>\n<p>Nope. I got an exception, but my code in the Catch script block did not run. You can only catch terminating exceptions. In order for my Try\/Catch to work properly, I have to make sure that if there is an exception it gets treated as a terminating exception. The best way is to use the common -ErrorAction parameter and set it to Stop.<\/p>\n<p><code Lang=\"PowerShell\"><br \/>\nTry {<br \/>\n  Get-Service Foo -ErrorAction Stop<br \/>\n}<\/p>\n<p>Catch {<br \/>\n  Write-Warning \"Oops\"<br \/>\n  Write-Warning $_.Exception.Message<br \/>\n}<br \/>\n<\/code><\/p>\n<p>The parameter has an alias of -ea which you'll often see used. Now let's see what happens:<\/p>\n<p><code lang=\"DOS\"><br \/>\nPS C:\\work> .\\trydemo.ps1<br \/>\nWARNING: Oops<br \/>\nWARNING: Cannot find any service with service name 'Foo'.<br \/>\nPS C:\\work><br \/>\n<\/code><\/p>\n<p>That's what I was expecting. Now for the tricky part. Look at this variation.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\nTry {<br \/>\n  Get-Service -ComputerName Bogus<br \/>\n}<\/p>\n<p>Catch {<br \/>\n  Write-Warning \"Oops\"<br \/>\n  Write-Warning $_.Exception.Message<br \/>\n}<br \/>\n<\/code><\/p>\n<p>What happens when I run this?<\/p>\n<p><code lang=\"DOS\"><br \/>\nPS C:\\work> .\\trydemo.ps1<br \/>\nWARNING: Oops<br \/>\nWARNING: Cannot open Service Control Manager on computer 'Bogus'. This<br \/>\noperation might require other privileges.<br \/>\n<\/code><\/p>\n<p>How about that? Even without -erroraction, my catch code still ran. Based on this I can safely deduce that the remote connection failure created a terminating exception. But without a lot of trial and error I think it is impossible to know in advance what type of error will throw a terminating exception and what won't. Personally, I think the best thing is to always use -ErrorAction stop on a cmdlet in a Try scriptblock to guarantee you will always get a terminating exception.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In looking at entries in this year&#8217;s Scripting Games, as well as posts I see in PowerShell forums, I thought I&#8217;d post a short guide to properly using Try\/Catch. This is the way I think it should be used. Let&#8217;s start with a Try\/Catch block that might look ok. Try { Get-Service Foo } Catch&#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":[4,8],"tags":[370,534,540,227],"class_list":["post-2175","post","type-post","status-publish","format-standard","hentry","category-powershell","category-scripting","tag-errorhandling","tag-powershell","tag-scripting","tag-trycatch"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Try and Catch Me If You Can &#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\/powershell\/2175\/try-and-catch-me-if-you-can\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Try and Catch Me If You Can &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"In looking at entries in this year&#039;s Scripting Games, as well as posts I see in PowerShell forums, I thought I&#039;d post a short guide to properly using Try\/Catch. This is the way I think it should be used. Let&#039;s start with a Try\/Catch block that might look ok. Try { Get-Service Foo } Catch...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/2175\/try-and-catch-me-if-you-can\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2012-04-05T13:24:02+00:00\" \/>\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=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2175\\\/try-and-catch-me-if-you-can\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2175\\\/try-and-catch-me-if-you-can\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Try and Catch Me If You Can\",\"datePublished\":\"2012-04-05T13:24:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2175\\\/try-and-catch-me-if-you-can\\\/\"},\"wordCount\":272,\"commentCount\":7,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"keywords\":[\"ErrorHandling\",\"PowerShell\",\"Scripting\",\"TryCatch\"],\"articleSection\":[\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2175\\\/try-and-catch-me-if-you-can\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2175\\\/try-and-catch-me-if-you-can\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2175\\\/try-and-catch-me-if-you-can\\\/\",\"name\":\"Try and Catch Me If You Can &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"datePublished\":\"2012-04-05T13:24:02+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2175\\\/try-and-catch-me-if-you-can\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2175\\\/try-and-catch-me-if-you-can\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2175\\\/try-and-catch-me-if-you-can\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Try and Catch Me If You Can\"}]},{\"@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":"Try and Catch Me If You Can &#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\/powershell\/2175\/try-and-catch-me-if-you-can\/","og_locale":"en_US","og_type":"article","og_title":"Try and Catch Me If You Can &#8226; The Lonely Administrator","og_description":"In looking at entries in this year's Scripting Games, as well as posts I see in PowerShell forums, I thought I'd post a short guide to properly using Try\/Catch. This is the way I think it should be used. Let's start with a Try\/Catch block that might look ok. Try { Get-Service Foo } Catch...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2175\/try-and-catch-me-if-you-can\/","og_site_name":"The Lonely Administrator","article_published_time":"2012-04-05T13:24:02+00:00","author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2175\/try-and-catch-me-if-you-can\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2175\/try-and-catch-me-if-you-can\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Try and Catch Me If You Can","datePublished":"2012-04-05T13:24:02+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2175\/try-and-catch-me-if-you-can\/"},"wordCount":272,"commentCount":7,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"keywords":["ErrorHandling","PowerShell","Scripting","TryCatch"],"articleSection":["PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/2175\/try-and-catch-me-if-you-can\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2175\/try-and-catch-me-if-you-can\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2175\/try-and-catch-me-if-you-can\/","name":"Try and Catch Me If You Can &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"datePublished":"2012-04-05T13:24:02+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2175\/try-and-catch-me-if-you-can\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/2175\/try-and-catch-me-if-you-can\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2175\/try-and-catch-me-if-you-can\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Try and Catch Me If You Can"}]},{"@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":1423,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1423\/warning-signs\/","url_meta":{"origin":2175,"position":0},"title":"Warning Signs","author":"Jeffery Hicks","date":"May 11, 2011","format":false,"excerpt":"I was working on a project with an advanced PowerShell function. One of the goals was to take advantage of the common parameters like -ErrorVariable and -WarningVariable so that when you run the function you can save errors and warnings and work with them later. Turns out one of these\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":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/05\/warningvariable-300x184.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":7700,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7700\/active-directory-objects-and-the-powershell-pipeline\/","url_meta":{"origin":2175,"position":1},"title":"Active Directory Objects and the PowerShell Pipeline","author":"Jeffery Hicks","date":"September 28, 2020","format":false,"excerpt":"This article is something I've been meaning to write for sometime. As often as I tell people PowerShell is easy to use once you understand its core concepts, that isn't always the case.\u00a0 This is a problem my friend Gladys Kravitz brought to my attention some time ago. Like her,\u2026","rel":"","context":"In &quot;Active Directory&quot;","block_context":{"text":"Active Directory","link":"https:\/\/jdhitsolutions.com\/blog\/category\/active-directory\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/Get-bits-revised-ad.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/Get-bits-revised-ad.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/Get-bits-revised-ad.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/Get-bits-revised-ad.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/Get-bits-revised-ad.jpg?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":544,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/544\/potential-pipeline-pitfall\/","url_meta":{"origin":2175,"position":2},"title":"Potential Pipeline Pitfall","author":"Jeffery Hicks","date":"January 11, 2010","format":false,"excerpt":"Last week I was helping someone out in the PowerShell forum at ScriptingAnswers.com. The specific problem is irrelevant;l however I\u00a0 learned something in the process that will affect how I write my own PowerShell functions from now on. Not being a developer I never picked up on this subtle (at\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":[]},{"id":7065,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7065\/powershell-paths-and-errors\/","url_meta":{"origin":2175,"position":3},"title":"PowerShell Paths and Errors","author":"Jeffery Hicks","date":"December 6, 2019","format":false,"excerpt":"As you write PowerShell scripts, it is important that you include error handling. Most of the time, this involves the use of Try\/Catch statements. The tricky thing with Try\/Catch is that you can only catch a terminating exception. There are a few cmdlets that by design will throw a terminating\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\/2019\/12\/image_thumb-13.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb-13.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb-13.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb-13.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":8526,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8526\/doing-more-with-myinvocation\/","url_meta":{"origin":2175,"position":4},"title":"Doing More with $MyInvocation","author":"Jeffery Hicks","date":"August 19, 2021","format":false,"excerpt":"Not that long ago someone made a comment to me on Twitter about something I had shared related to PowerShell. He wanted to know more about the $MyInvocation variable. This is something that isn't well documented, yet can be very useful in your PowerShell scripting. Let's take a look at\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\/08\/myinvocation-debug-vscode.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/myinvocation-debug-vscode.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/myinvocation-debug-vscode.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/myinvocation-debug-vscode.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":840,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/840\/pipelines-consoles-and-hosts\/","url_meta":{"origin":2175,"position":5},"title":"Pipelines, Consoles and Hosts","author":"Jeffery Hicks","date":"August 19, 2010","format":false,"excerpt":"I continue to come across a particular topic in discussion forums that causes many PowerShell beginners a lot of headaches and more than a little frustration. I know I've written about this before and I'm sure I'll cover it again, but when writing anything in PowerShell that you see in\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\/2010\/08\/write-demo.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2175","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=2175"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2175\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=2175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=2175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=2175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}