PowerShell One-Liner: What's the Function Name?
Rather than have to put the function's name in the error mesage (and then forgetting to change it when I copy/paste/rename/modify it), here's a quick function that I can embed in the error message to spit out the function's name:
function Get-FunctionName {
(Get-Variable MyInvocation -Scope 1).Value.MyCommand.Name;
}
-scope 1 means to get it for the calling function, which is what we need.
Comments
Anonymous
May 16, 2015
These days, I just use $MyInvocation.MyCommand.NameAnonymous
July 08, 2015
Very useful. Thanks! :)