Powershell Tip: Using Enum as Parameter Validation


An Enum type is a data type that enables a variable to be a set of predefined constants. The variable must be equal to one of the values that have been predefined for it. Enums can be more descriptive rather using just a number.

Enums are used to declare an enumeration, a distinct type that consists of a set of named constants called the enumerator list, like an example in below Animation –

Tip1

But, the Powershell Tip I learned today is that this could be used even for Parameter Validation inside a Function. To restrict the input to a list of predefined enumerations. like in below example.

tip

If you’ll try giving a Value outside the defined it will give you errors.

error

Useful – Right? 🙂

Prateek Singh

Advertisements

2 thoughts on “Powershell Tip: Using Enum as Parameter Validation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s