Parameter validation

Validating parameters in a Powershell function

Parameter validation In this article we will talk about an option available in Powershell: the validation of parameters The purpose of this option is, as the name suggests, to validate that a parameter passed to a function is indeed the one we expect. Throughout this article we will keep the following script as a guideline. function Do-SomeThing { [CmdletBinding()] param ( [String[]]$ComputerName, [Int]$Age ) begin { #The value of computername must not be null or empty if (($null -eq $ComputerName) -or ($ComputerName -eq "")) { throw "ComputerName cannot be empty or null" } #Test to verify that the computer name does not exceed 13 characters If ($ComputerName. [Read More]