How can I retrieve the name of the function that is currently running in powershell? Here is an example of what I want:
Function write-FunctionName
{
write-host "The name of this function is: *SomethingGoesHereButWhat?*"
}
Then when I execute it, it will display this:
>write-FunctionName
The name of this function is: write-FunctioName
>
Can this be done? If so how?
Method 1: Get Function Name in Python using function. func_name.
Use the __name__ Property to Get the Function Name in Python __name__ . It will then return the function name as a string. The below example declares two functions, calls them, and prints out their function names. Note that this solution also works with the imported and pre-defined functions.
The $MyInvocation
variable contains information about whatever is currently executing:
Function write-FunctionName { write-host ("The name of this function is: {0} " -f $MyInvocation.MyCommand) }
For more information, see get-help about_automatic_variables
, or the technet site here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With