Powershell: find the name of the file where the function is defined

Given the function object (i.e. $f = gi Function:\myfunc ), you can find the file name and other information (for example, line number) of the file in which the function is declared?

+6
source share
1 answer

You are on the right track with gi . The ScriptBlock element of the function object has File and StartPosition among its properties:

 (gi function:\prompt).ScriptBlock.File 

Or you can just go with:

 ${Function:myfunc}.File 
+4
source

All Articles