'Powershell functions defined in profile

I have a function called GreatFuncion1 defined in "profile.ps1"

loads when powershell launches and works ok

how can I get the path where this function was defined from Powershell?
usually i'll do this with:

(Get-Command -commandtype function -name **GreatFunction1**).Module

but in this case it returns $null, so I can't get a path from here...
?is there any other way??
I need to know the path to the file from what some function was loaded...



Solution 1:[1]

Try `${function:GreatFunction1}.File this should give you the full path for wherever your function is coming from

https://stackoverflow.com/a/16008967/13160707

Solution 2:[2]

Taking what @nikkelly mentioned in their answer and generalizing it, you could accomplish this by first accessing the ScriptBlock property of the function, and then the File property of the ScriptBlock.

Here are two equivalent examples:

(Get-ChildItem Function: | Where-Object Name -like "**GreatFunction1**").ScriptBlock.File
(Get-Command -CommandType Function -Name **GreatFunction1**).ScriptBlock.File

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 nikkelly
Solution 2 Shenk