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 year is for a given…
Tag: Validation
Variable Validation
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 v2 scripts and functions we…
PowerShell Scripting with [ValidateNotNullorEmpty]
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 the user decides to use…
PowerShell Scripting with [ValidateCount]
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 want to process more than…
PowerShell Scripting with [ValidateLength]
In continuing the exploration of parameter validation attributes, today we’ll look at [ValidateLength()]. You can use this attribute in your PowerShell scripting to validate that a parameter value is at least a certain length and no more and a certain length. In other words, it has to be just right. Here’s what it looks like:…
PowerShell Scripting with [ValidatePattern]
I’ve been writing about a number of parameters attributes you can include in your PowerShell scripting to validate parameter values. Today I want to cover using a regular expression pattern to validate a parameter value. I’m going to assume you have a rudimentary knowledge of how to use regular expressions in PowerShell. If not, there…
PowerShell Scripting with [ValidateSet]
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, specify a comma separated list…
PowerShell Scripting with [ValidateScript]
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…