Powershell Binary Module - Parameter Validation

I am learning PowerShell and a good friend recommended this excellent article on Binaries in PowerShell to me.

I am planning on porting some of the console applications that I have created for use as binaries.

And one of the things I would like to do is validate my PowerShell parameters correctly.

I found this post:

http://huddledmasses.org/better-error-messages-for-powershell-validatepattern/

But I'm not sure if this is the approach I should be following, I mean, I even planned to use DataAnnotations to check my PowerShell parameters in my binary module

In the near future, I plan to start using more PowerShell directly, but at the same time I just want to convert my Console apps to PowerShell binaries.

Could you guys point me in the right direction?

I just want to know if there is a PowerShell way to do something in a binary to vlaidate my parameters

+3


source to share


1 answer


Jaykul's suggestion is more about how to get new validators for my PowerShell code. Instead, I would start with the built-in ones and would only do extra work when needed.

You will find several at System.Management.Automation:



  • ValidateArgumentsAttribute
  • ValidateEnumeratedArgumentsAttribute
  • ValidateLengthAttribute
  • ValidateRangeAttribute
  • ValidatePatternAttribute
  • ValidateScriptAttribute
  • ValidateCountAttribute
  • ValidateSetAttribute
  • ValidateNotNullAttribute
  • ValidateNotNullOrEmptyAttribute

They are documented on MSDN like ValidateSet Docs .

+5


source







All Articles