{"id":7065,"date":"2019-12-06T09:18:37","date_gmt":"2019-12-06T14:18:37","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=7065"},"modified":"2019-12-06T09:18:43","modified_gmt":"2019-12-06T14:18:43","slug":"powershell-paths-and-errors","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7065\/powershell-paths-and-errors\/","title":{"rendered":"PowerShell Paths and Errors"},"content":{"rendered":"<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image-9.png\"><img loading=\"lazy\" decoding=\"async\" style=\"margin: 0px 5px 5px 0px; float: left; display: inline; background-image: none;\" title=\"image\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb-9.png\" alt=\"image\" width=\"230\" height=\"154\" align=\"left\" border=\"0\" \/><\/a>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 exception. But you have no way of knowing in advance. The best way to guarantee your Try\/Catch block will work is to set the common -ErrorAction parameter to Stop. Only then are you guaranteed a terminating exception and that the code in your Catch block will run.<\/p>\n<p>However, there is another situation where this can be tricky, and this is a question that came up the other day. How can you create a terminating exception for a file not found situation?<\/p>\n<p>For example, you might try code like this:<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">Try {\n    Test-Path Foo:\\Bar.txt -ErrorAction Stop\n}\nCatch {\n    Write-Warning \"I failed\"\n}\n<\/pre>\n<p>When you run this code, you'll get False. The code in the Catch block never executes.\u00a0 This is because the <a title=\"Read online help for this command\" href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=113418\" target=\"_blank\" rel=\"noopener noreferrer\">Test-Path<\/a> cmdlet writes a boolean (True\/False) value to the pipeline. If the file or path doesn't exist that isn't an error. Although. you can make it one. Here's a variation on the preceding code.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">$path = \"Foo:\\Bar.txt\"\nTry {\n    if (-Not (Test-Path $path)) {\n        Throw \"Failed to find the $path\"\n    }\n}\nCatch {\n    Write-Warning \"I caught an exception\"\n    $_\n}\n<\/pre>\n<p>This works.<\/p>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image-10.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"missing file exception\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb-10.png\" alt=\"missing file exception\" width=\"1028\" height=\"168\" border=\"0\" \/><\/a><\/p>\n<p>Personally, I would use a simple If statement. But obviously I can't speak to everyone's use cases.<\/p>\n<p>But perhaps instead of using Test-Path you might consider a different cmdlet.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">$path = \"Foo:\\Bar.txt\"\nTry {\n    Resolve-Path -Path $path -ErrorAction Stop\n}\nCatch {\n    Write-Warning \"I caught an exception\"\n    $_\n}\n<\/pre>\n<p><a title=\"Read online help for this command\" href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=113384\" target=\"_blank\" rel=\"noopener noreferrer\">Resolve-Path<\/a> is intended to resolve wild-card characters in a path. If the path doesn't exist, the cmdlet will generate an exception. In my Try\/Catch block I am forcing it to be terminating.<\/p>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image-11.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"Validing Paths with Resolve-Path\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb-11.png\" alt=\"Validing Paths with Resolve-Path\" width=\"1028\" height=\"175\" border=\"0\" \/><\/a><\/p>\n<p>By the way, you could also use <a title=\"Read online help for this command\" href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=113289\" target=\"_blank\" rel=\"noopener noreferrer\">Convert-Path<\/a>. One thing to be aware of is that these cmdlets will write objects to the pipeline, which may be exactly what you need. You may need to convert or resolve a path into a true file system path maybe to run some non-PowerShell command against it.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">$path = \"$env:windir\\notepad.exe\"\nTry {\n    $rPath = Resolve-Path -Path $path -ErrorAction Stop\n}\nCatch {\n    Write-Warning \"I caught an exception\"\n    $_\n}\nWrite-Host \"Using $rPath\" -ForegroundColor green\n<\/pre>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image-12.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"Using Resolve-Path\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb-12.png\" alt=\"Using Resolve-Path\" width=\"979\" height=\"437\" border=\"0\" \/><\/a><\/p>\n<p>One file option is to use <a title=\"Read online help for this command\" href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=113319\" target=\"_blank\" rel=\"noopener noreferrer\">Get-Item<\/a>.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">$path = \"Foo:\\Bar.txt\"\nTry {\n   [void](Get-Item -Path $path -ErrorAction Stop)\n}\nCatch {\n    Write-Warning \"I caught an exception\"\n    $_\n}\n<\/pre>\n<p>In this case I don't need the actual file object so I'm casting the results of the command as nothing.<\/p>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image-13.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"Using Get-Item to validate a path in PowerShell\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb-13.png\" alt=\"Using Get-Item to validate a path in PowerShell\" width=\"1028\" height=\"386\" border=\"0\" \/><\/a><\/p>\n<p>I'm not going to tell you that any one of these techniques is better than the other. It truly depends on the overall needs of your scripting project. I encourage you to read full cmdlet help and examples for the commands I've shown here. There may be additional parameters that can help you fine-tune your testing and error handling.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 exception. But you have no&#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":"New on the blog: #PowerShell Paths and Terminating Exceptions","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":[4],"tags":[370,534,540],"class_list":["post-7065","post","type-post","status-publish","format-standard","hentry","category-powershell","tag-errorhandling","tag-powershell","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PowerShell Paths and Errors &#8226; The Lonely Administrator<\/title>\n<meta name=\"description\" content=\"Here are some techniques for testing paths in PowerShell and generating terminating exceptions if they are not found. Check out the Try\/Catch examples.\" \/>\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\/7065\/powershell-paths-and-errors\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PowerShell Paths and Errors &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"Here are some techniques for testing paths in PowerShell and generating terminating exceptions if they are not found. Check out the Try\/Catch examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/7065\/powershell-paths-and-errors\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2019-12-06T14:18:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-12-06T14:18:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb-9.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\\\/powershell\\\/7065\\\/powershell-paths-and-errors\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7065\\\/powershell-paths-and-errors\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"PowerShell Paths and Errors\",\"datePublished\":\"2019-12-06T14:18:37+00:00\",\"dateModified\":\"2019-12-06T14:18:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7065\\\/powershell-paths-and-errors\\\/\"},\"wordCount\":416,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7065\\\/powershell-paths-and-errors\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/12\\\/image_thumb-9.png\",\"keywords\":[\"ErrorHandling\",\"PowerShell\",\"Scripting\"],\"articleSection\":[\"PowerShell\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7065\\\/powershell-paths-and-errors\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7065\\\/powershell-paths-and-errors\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7065\\\/powershell-paths-and-errors\\\/\",\"name\":\"PowerShell Paths and Errors &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7065\\\/powershell-paths-and-errors\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7065\\\/powershell-paths-and-errors\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/12\\\/image_thumb-9.png\",\"datePublished\":\"2019-12-06T14:18:37+00:00\",\"dateModified\":\"2019-12-06T14:18:43+00:00\",\"description\":\"Here are some techniques for testing paths in PowerShell and generating terminating exceptions if they are not found. Check out the Try\\\/Catch examples.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7065\\\/powershell-paths-and-errors\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7065\\\/powershell-paths-and-errors\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7065\\\/powershell-paths-and-errors\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/12\\\/image_thumb-9.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/12\\\/image_thumb-9.png\",\"width\":230,\"height\":154},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7065\\\/powershell-paths-and-errors\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PowerShell Paths and Errors\"}]},{\"@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":"PowerShell Paths and Errors &#8226; The Lonely Administrator","description":"Here are some techniques for testing paths in PowerShell and generating terminating exceptions if they are not found. Check out the Try\/Catch examples.","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\/7065\/powershell-paths-and-errors\/","og_locale":"en_US","og_type":"article","og_title":"PowerShell Paths and Errors &#8226; The Lonely Administrator","og_description":"Here are some techniques for testing paths in PowerShell and generating terminating exceptions if they are not found. Check out the Try\/Catch examples.","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7065\/powershell-paths-and-errors\/","og_site_name":"The Lonely Administrator","article_published_time":"2019-12-06T14:18:37+00:00","article_modified_time":"2019-12-06T14:18:43+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb-9.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\/powershell\/7065\/powershell-paths-and-errors\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7065\/powershell-paths-and-errors\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"PowerShell Paths and Errors","datePublished":"2019-12-06T14:18:37+00:00","dateModified":"2019-12-06T14:18:43+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7065\/powershell-paths-and-errors\/"},"wordCount":416,"commentCount":0,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7065\/powershell-paths-and-errors\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb-9.png","keywords":["ErrorHandling","PowerShell","Scripting"],"articleSection":["PowerShell"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/7065\/powershell-paths-and-errors\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7065\/powershell-paths-and-errors\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7065\/powershell-paths-and-errors\/","name":"PowerShell Paths and Errors &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7065\/powershell-paths-and-errors\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7065\/powershell-paths-and-errors\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb-9.png","datePublished":"2019-12-06T14:18:37+00:00","dateModified":"2019-12-06T14:18:43+00:00","description":"Here are some techniques for testing paths in PowerShell and generating terminating exceptions if they are not found. Check out the Try\/Catch examples.","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7065\/powershell-paths-and-errors\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/7065\/powershell-paths-and-errors\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7065\/powershell-paths-and-errors\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb-9.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb-9.png","width":230,"height":154},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7065\/powershell-paths-and-errors\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"PowerShell Paths and Errors"}]},{"@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":1413,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1413\/get-registry-size-and-age\/","url_meta":{"origin":7065,"position":0},"title":"Get Registry Size and Age","author":"Jeffery Hicks","date":"May 4, 2011","format":false,"excerpt":"I'm not sure why the registry has been on my mind lately. I probably need a vacation to get out more. But I put together a relatively simple Windows PowerShell function to retrieve registry statistics that you might find useful. My Get-Registry function will return information about the size of\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\/2011\/05\/registry.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2175,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2175\/try-and-catch-me-if-you-can\/","url_meta":{"origin":7065,"position":1},"title":"Try and Catch Me If You Can","author":"Jeffery Hicks","date":"April 5, 2012","format":false,"excerpt":"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\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":3036,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3036\/test-64-bit-operating-system\/","url_meta":{"origin":7065,"position":2},"title":"Test 64-Bit Operating System","author":"Jeffery Hicks","date":"May 16, 2013","format":false,"excerpt":"One of the great features of PowerShell is how much you can get from a relatively simple one line command. For example. you might want to test if a computer is running a 64-bit operating system. You can find out with a command as simple as this. PS C:\\> (get-wmiobject\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"osarchitecture-fail","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/osarchitecture-fail-1024x298.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/osarchitecture-fail-1024x298.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/osarchitecture-fail-1024x298.png?resize=525%2C300 1.5x"},"classes":[]},{"id":2900,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2900\/test-hyper-v-vhd-folders-with-powershell\/","url_meta":{"origin":7065,"position":3},"title":"Test Hyper-V VHD Folders with PowerShell","author":"Jeffery Hicks","date":"April 1, 2013","format":false,"excerpt":"I've recently added a USB 3.0 Express Card adapter to my laptop to provide USB 3.0 functionality. The added performance is very useful in my Hyper-V setup. However, I am running into a glitch that I have yet to figure out where the external drives (the Express card has 2\u2026","rel":"","context":"In &quot;Hyper-V&quot;","block_context":{"text":"Hyper-V","link":"https:\/\/jdhitsolutions.com\/blog\/category\/hyper-v\/"},"img":{"alt_text":"test-vhdpath","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/test-vhdpath-1024x314.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/test-vhdpath-1024x314.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/test-vhdpath-1024x314.png?resize=525%2C300 1.5x"},"classes":[]},{"id":2935,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/","url_meta":{"origin":7065,"position":4},"title":"Get CIMInstance from PowerShell 2.0","author":"Jeffery Hicks","date":"April 10, 2013","format":false,"excerpt":"I love the new CIM cmdlets in PowerShell 3.0. Querying WMI is a little faster because the CIM cmdlets query WMI using the WSMAN protocol instead of DCOM. The catch is that remote computers must be running PowerShell 3 which includes the latest version of the WSMAN protocol and the\u2026","rel":"","context":"In &quot;Powershell 3.0&quot;","block_context":{"text":"Powershell 3.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-3-0\/"},"img":{"alt_text":"get-ciminstance-error","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-ciminstance-error-300x145.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2524,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2524\/variable-validation\/","url_meta":{"origin":7065,"position":5},"title":"Variable Validation","author":"Jeffery Hicks","date":"October 26, 2012","format":false,"excerpt":"In PowerShell v3 there is a new feature you might not be aware of that could save you pain and headaches. This is something you could use in scripting as well as the console. In fact, I think using it in the console is an especially smart idea. In PowerShell\u2026","rel":"","context":"In &quot;Powershell 3.0&quot;","block_context":{"text":"Powershell 3.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-3-0\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/05\/talkbubble-v3-150x150.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7065","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=7065"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7065\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=7065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=7065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=7065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}