PowerShell use enumeration variables to define function parameters with smart hints _powershell

Source: Internet
Author: User
Tags define function

This article describes how you can set a function to use an enumeration variable to intelligently cue parameter values when customizing the PowerShell function. The enumeration type can be. NET Framework, the system enumeration type.

In the PowerShell 3.0 version, a new feature appears, which is the smart hint for parameter values. Of course, it's not just anywhere. Smart Cue parameter values, but only in Ise. Of course, the so-called ISE is an integrated development environment with PowerShell.

This article describes the use of the system's own enumerated variables as an enumeration option for smart hints.

Let's take a look at the Select-color again.

Copy Code code as follows:

function Select-color
{
Param
[Validateset (' Red ', ' Green ', ' Blue ')]
$Color
)
"You chose $Color"
}

Here is a list of smart hints using Valiateset as a parameter value, and we can modify it to use an enumeration type as a smart hint list for parameter values.

Copy Code code as follows:

function Select-color
{
Param
[System.consolecolor]
$Color
)
"You chose $Color"
}

OK, as you can see, the changes are simple, and the set of valid values [Validateset (' Red ', ' Green ', ' Blue ')] is changed to the system's own enumeration type [System.consolecolor], which also enables you to implement smart hints for parameter values.

About the PowerShell function to use enumerated variables as a parameter smart hint, this article on the introduction of so many, I hope to help you, thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.