The PowerShell function specifies the return value type instance _powershell

Source: Internet
Author: User

This article describes how to set the data type of the return value when customizing the PowerShell function. The return value of the PowerShell function can have a type or no type, similar to an input parameter.

To define the return value type of the PowerShell function, use the OUTPUTTYPE directive. The definition of the return value type can be implemented before this instruction is placed in the param instruction.

Copy Code code as follows:

function Test-intellisense
{
[OutputType (' System.DateTime ')]
Param ()
Return get-date
}

In the above function, we use [OutputType (' System.DateTime ')] to define the return value as a DateTime type. When we call, we use the
Copy Code code as follows:
$result = Test-intellisense

When you enter $result in the console, you should see a smart hint of the $result variable as datetime. Of course, this must be in a later version of PowerShell v3.0.

About PowerShell definition function return value type, this article introduces so many, hope to be helpful to 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.