{"id":2193,"date":"2012-04-12T09:57:41","date_gmt":"2012-04-12T13:57:41","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=2193"},"modified":"2012-04-12T09:57:41","modified_gmt":"2012-04-12T13:57:41","slug":"powershell-scripting-with-validatescript","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2193\/powershell-scripting-with-validatescript\/","title":{"rendered":"PowerShell Scripting with [ValidateScript]"},"content":{"rendered":"<p>The last few days we've been looking at parameter validation attributes you might use in a script of function. <a href=\"http:\/\/jdhitsolutions.com\/blog\/2012\/04\/powershell-scripting-with-validaterange\/\" target=\"_blank\">Yesterday<\/a> I wrote about [ValidateRange] and demonstrated how you might use it. That attribute works fine for any values that can be evaluated as numbers.  But dates are a different story. I got a comment with a suggestion for validating dates and at first glance it appears to work. For a very small range it might, but here's the code I was testing with.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\nParam (<br \/>\n[Parameter(Position=0,Mandatory=$True,HelpMessage=\"Enter a date\",ValueFromPipeline=$True)]<br \/>\n[ValidateRange(\"1\/1\/2012\",\"4\/1\/2012\")]<br \/>\n$Date<br \/>\n)<\/p>\n<p>Process {<br \/>\nwrite-host $date -ForegroundColor Green<br \/>\n}<br \/>\n<\/code><\/p>\n<p>I'm expecting date between 1\/1\/2012 and 4\/1\/2012. Anything else should throw an exception. Now watch what happens as I pipe some values to this:<\/p>\n<p><code Lang=\"DOS\"><br \/>\nPS S:\\> \"2\/12\/2012\",\"5\/1\/2012\",\"12\/1\/2011\",\"13\/2\/2012\" | .\\Demo-ValidateRange-Da<br \/>\nte.ps1<br \/>\n2\/12\/2012<br \/>\nC:\\scripts\\Demo-ValidateRange-Date.ps1 : Cannot validate argument on parameter<br \/>\n'Date'. The 5\/1\/2012 argument is greater than the maximum allowed range of 4\/1\/<br \/>\n2012. Supply an argument that is less than 4\/1\/2012 and then try the command ag<br \/>\nain.<br \/>\nAt line:1 char:79<br \/>\n+ \"2\/12\/2012\",\"5\/1\/2012\",\"12\/1\/2011\",\"13\/2\/2012\" | .\\Demo-ValidateRange-Date.ps<br \/>\n1 <<<<\n    + CategoryInfo          : InvalidData: (5\/1\/2012:String) [Demo-ValidateRan\n   ge-Date.ps1], ParameterBindingValidationException\n    + FullyQualifiedErrorId : ParameterArgumentValidationError,Demo-ValidateRa\n   nge-Date.ps1\n\n12\/1\/2011\n13\/2\/2012\n<\/code><\/p>\n<p>Values that are outside the range and even those that are bogus still are accepted. If I cast $date to [DateTime] which is what I would normally do, then nothing works at all. But that's fine because there is another attribute that is better suited to this task: [ValidateScript()].<\/p>\n<p>To use this attribute we'll insert a scriptblock inside the parentheses. The scriptblock can be as complicated as you need it to be, but it must evaluate to either True or False. Use $_ to indicate the parameter value. So using my datetime example, I might use a validation script like this:<\/p>\n<p><code lang=\"PowerShell\"><br \/>\nParam (<br \/>\n[Parameter(Position=0,Mandatory=$True,HelpMessage=\"Enter a date\",ValueFromPipeline=$True)]<br \/>\n[ValidateScript( {<br \/>\n [datetime]$start=\"1\/1\/2012\"<br \/>\n $end=Get-Date<br \/>\n ($_ -ge $start) -AND ($_ -le $end)<br \/>\n }<br \/>\n )]<br \/>\n[datetime]$Date<br \/>\n)<\/p>\n<p>Process {<br \/>\nwrite-host $date -ForegroundColor Green<br \/>\n}<br \/>\n<\/code><\/p>\n<p>With a validation script I have much more flexibility. Now look at the results:<\/p>\n<p><code lang=\"DOS\"><br \/>\nPS S:\\> \"2\/12\/2012\",\"5\/1\/2012\",\"3\/15\/2012\",\"12\/1\/2011\",\"13\/2\/2012\" | .\\Demo-Vali<br \/>\ndateScript-Date.ps1 | clip<br \/>\n2\/12\/2012 12:00:00 AM<br \/>\nC:\\scripts\\Demo-ValidateScript-Date.ps1 : Cannot validate argument on parameter<br \/>\n 'Date'. The \"<br \/>\n [datetime]$start=\"1\/1\/2012\"<br \/>\n $end=Get-Date<br \/>\n ($_ -ge $start) -AND ($_ -le $end)<br \/>\n \" validation script for the argument with value \"5\/1\/2012 12:00:00 AM\" did not<br \/>\n return true. Determine why the validation script failed and then try the comma<br \/>\nnd again.<br \/>\nAt line:1 char:92<br \/>\n+ \"2\/12\/2012\",\"5\/1\/2012\",\"3\/15\/2012\",\"12\/1\/2011\",\"13\/2\/2012\" | .\\Demo-ValidateS<br \/>\ncript-Date.ps1 <<<<  | clip\n    + CategoryInfo          : InvalidData: (5\/1\/2012:String) [Demo-ValidateScr\n   ipt-Date.ps1], ParameterBindingValidationException\n    + FullyQualifiedErrorId : ParameterArgumentValidationError,Demo-ValidateSc\n   ript-Date.ps1\n\n3\/15\/2012 12:00:00 AM\nC:\\scripts\\Demo-ValidateScript-Date.ps1 : Cannot validate argument on parameter\n 'Date'. The \"\n [datetime]$start=\"1\/1\/2012\"\n $end=Get-Date\n ($_ -ge $start) -AND ($_ -le $end)\n \" validation script for the argument with value \"12\/1\/2011 12:00:00 AM\" did no\nt return true. Determine why the validation script failed and then try the comm\nand again.\nAt line:1 char:92\n+ \"2\/12\/2012\",\"5\/1\/2012\",\"3\/15\/2012\",\"12\/1\/2011\",\"13\/2\/2012\" | .\\Demo-ValidateS\ncript-Date.ps1 <<<<  | clip\n    + CategoryInfo          : InvalidData: (12\/1\/2011:String) [Demo-ValidateSc\n   ript-Date.ps1], ParameterBindingValidationException\n    + FullyQualifiedErrorId : ParameterArgumentValidationError,Demo-ValidateSc\n   ript-Date.ps1\n\nC:\\scripts\\Demo-ValidateScript-Date.ps1 : The input object cannot be bound to a\nny parameters for the command either because the command does not take pipeline\n input or the input and its properties do not match any of the parameters that\ntake pipeline input.\nAt line:1 char:92\n+ \"2\/12\/2012\",\"5\/1\/2012\",\"3\/15\/2012\",\"12\/1\/2011\",\"13\/2\/2012\" | .\\Demo-ValidateS\ncript-Date.ps1 <<<<  \n    + CategoryInfo          : InvalidArgument: (13\/2\/2012:String) [Demo-Valida\n   teScript-Date.ps1], ParameterBindingException\n    + FullyQualifiedErrorId : InputObjectNotBound,Demo-ValidateScript-Date.ps1\n<\/code><\/p>\n<p>The valid dates pass, dates outside the range fail the validation test and the last value which isn't a legal date also fails but with a slightly different error message. As with all of the validation attributes I could have inserted this code into the body of my script and thrown my own errors. That choice is up to you. [ValidateScript()] isn't difficult to use. Just remember to insert your commands into a scriptblock, use $_ for the parameter value, and make sure the scriptblock writes either $True or $False.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The last few days we&#8217;ve been looking at parameter validation attributes you might use in a script of function. Yesterday I wrote about [ValidateRange] and demonstrated how you might use it. That attribute works fine for any values that can be evaluated as numbers. But dates are a different story. I got a comment with&#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":[307,534,82,540,372],"class_list":["post-2193","post","type-post","status-publish","format-standard","hentry","category-powershell","category-scripting","tag-parameter","tag-powershell","tag-scriptblock","tag-scripting","tag-validation"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PowerShell Scripting with [ValidateScript] &#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\/2193\/powershell-scripting-with-validatescript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PowerShell Scripting with [ValidateScript] &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"The last few days we&#039;ve been looking at parameter validation attributes you might use in a script of function. Yesterday I wrote about [ValidateRange] and demonstrated how you might use it. That attribute works fine for any values that can be evaluated as numbers. But dates are a different story. I got a comment with...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/2193\/powershell-scripting-with-validatescript\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2012-04-12T13:57:41+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\\\/2193\\\/powershell-scripting-with-validatescript\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2193\\\/powershell-scripting-with-validatescript\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"PowerShell Scripting with [ValidateScript]\",\"datePublished\":\"2012-04-12T13:57:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2193\\\/powershell-scripting-with-validatescript\\\/\"},\"wordCount\":319,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"keywords\":[\"parameter\",\"PowerShell\",\"ScriptBlock\",\"Scripting\",\"Validation\"],\"articleSection\":[\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2193\\\/powershell-scripting-with-validatescript\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2193\\\/powershell-scripting-with-validatescript\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2193\\\/powershell-scripting-with-validatescript\\\/\",\"name\":\"PowerShell Scripting with [ValidateScript] &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"datePublished\":\"2012-04-12T13:57:41+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2193\\\/powershell-scripting-with-validatescript\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2193\\\/powershell-scripting-with-validatescript\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2193\\\/powershell-scripting-with-validatescript\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PowerShell Scripting with [ValidateScript]\"}]},{\"@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 Scripting with [ValidateScript] &#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\/2193\/powershell-scripting-with-validatescript\/","og_locale":"en_US","og_type":"article","og_title":"PowerShell Scripting with [ValidateScript] &#8226; The Lonely Administrator","og_description":"The last few days we've been looking at parameter validation attributes you might use in a script of function. Yesterday I wrote about [ValidateRange] and demonstrated how you might use it. That attribute works fine for any values that can be evaluated as numbers. But dates are a different story. I got a comment with...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2193\/powershell-scripting-with-validatescript\/","og_site_name":"The Lonely Administrator","article_published_time":"2012-04-12T13:57:41+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\/2193\/powershell-scripting-with-validatescript\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2193\/powershell-scripting-with-validatescript\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"PowerShell Scripting with [ValidateScript]","datePublished":"2012-04-12T13:57:41+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2193\/powershell-scripting-with-validatescript\/"},"wordCount":319,"commentCount":2,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"keywords":["parameter","PowerShell","ScriptBlock","Scripting","Validation"],"articleSection":["PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/2193\/powershell-scripting-with-validatescript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2193\/powershell-scripting-with-validatescript\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2193\/powershell-scripting-with-validatescript\/","name":"PowerShell Scripting with [ValidateScript] &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"datePublished":"2012-04-12T13:57:41+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2193\/powershell-scripting-with-validatescript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/2193\/powershell-scripting-with-validatescript\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2193\/powershell-scripting-with-validatescript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"PowerShell Scripting with [ValidateScript]"}]},{"@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":2188,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2188\/powershell-scripting-with-validaterange\/","url_meta":{"origin":2193,"position":0},"title":"PowerShell Scripting with [ValidateRange]","author":"Jeffery Hicks","date":"April 11, 2012","format":false,"excerpt":"After my post yesterday on using the ValidateScript attribute with PSCredentials, I thought you might find it helpful to have a brief discussion on some other parameter validation attributes such as [ValidateRange()]. You can use this attribute if you want to verify that a given parameter value falls between some\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":2206,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2206\/powershell-scripting-with-validateset\/","url_meta":{"origin":2193,"position":1},"title":"PowerShell Scripting with [ValidateSet]","author":"Jeffery Hicks","date":"April 16, 2012","format":false,"excerpt":"Today we'll continue our exploration of the parameter validation attributes you can use in you PowerShell scripting. We've already looked at [ValidateRange] and [ValidateScript]. Another attribute you are likely to use is [ValidateSet()]. You can use this to verify that the parameter value belongs to a pre-defined set. To use,\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":3377,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3377\/friday-fun-get-day-of-the-year-with-powershell\/","url_meta":{"origin":2193,"position":2},"title":"Friday Fun: Get Day of the Year with PowerShell","author":"Jeffery Hicks","date":"August 30, 2013","format":false,"excerpt":"Earlier this week I was having some fun with @EnergizedTech on Twitter, playing around with dates in PowerShell. I'm not even sure where we started but the experience got me thinking and it's Friday so let's have some fun. While I can easily find out what the day of the\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"calendar","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/08\/calendar.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2306,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2306\/powershell-scripting-with-validatenotnullorempty\/","url_meta":{"origin":2193,"position":3},"title":"PowerShell Scripting with [ValidateNotNullorEmpty]","author":"Jeffery Hicks","date":"May 15, 2012","format":false,"excerpt":"I've been writing about the different parameter validation attributes that you can use in your PowerShell scripting. One that I use in practically every script is [ValidateNotNullorEmpty()]. This validation will ensure that something is passed as a parameter value. I'm not talking about making a parameter mandatory; only that if\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\/2012\/05\/validatenotnullorempty-300x141.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2524,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2524\/variable-validation\/","url_meta":{"origin":2193,"position":4},"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":[]},{"id":2247,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2247\/powershell-scripting-with-validatecount\/","url_meta":{"origin":2193,"position":5},"title":"PowerShell Scripting with [ValidateCount]","author":"Jeffery Hicks","date":"April 26, 2012","format":false,"excerpt":"Here's another parameter validation attribute you might want to use in your PowerShell scripting and functions. If your parameter can take an array of values, you might want to limit that array to a certain size. For example, your parameter can take an array of computer names but you don't\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\/2012\/04\/validatecount-ok-300x66.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2193","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=2193"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2193\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=2193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=2193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=2193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}