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!