Private/GetFunctionDefinitionByFunction.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Function GetFunctionDefinitionByFunction {
    [CmdletBinding()]
    param (
        [parameter(ValueFromPipeline = $True)]
        $FunctionItem
    )

    if ($FunctionItem -is [PSCustomObject]) {
        # In case of Powershell v2
        $function.Body.Trim().Trim("{}")
    }
    else {
        # In case of Powershell v3+
        $function.Body.Extent.Text.Trim("{}")
    }
}