PowerShell Parameter Validation

It’s possible to validate input in PowerShell!

fun

out

There are eight built in functions:

  1. ValidateNotNull
  2. ValidateNotNullOrEmpty
  3. ValidateLength
  4. ValidateCount
  5. ValidateRange
  6. ValidateSet
  7. ValidatePattern
  8. ValidateScript

With dynamic typing,  I don’t see the importance of one through seven, but eight!  Is amazing.  Let’s say you need to have the function only fun as administrator.  You  can throw in a short script block that returns $true when run as admin.

admin

Happy PowerShell!

Leave a comment