What is $Function: variable?

Hi everyone,

Can anyone point me to a knowledge article for what the predefined $Function: variable is? I saw some examples on how its used online, but would like to read more about it.

Thanks,
Michael

There are a few different things you might be talking about. I would check out:

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-6

and

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scopes?view=powershell-6

$Function is a reference to the “Function Provider” psdrive (https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/providers/function-provider?view=powershell-6)

You can use it to reference functions stored in the session state.

IE.

cls
function test {
    Write-host "This is my function code" -ForegroundColor Green
}

$Function:test

test

Results:

    Write-host "This is my function code" -ForegroundColor Green

This is my function code

Notice how the first output is the code of the function itself, then the second output is the output of the function execution.