How can I get the current PowerShell executing file?
如果你在一个函数中,你会怎么做呢。
下面的示例在函数定义之外工作,而不是在函数内部。
echo ''
echo '******** outside function scope'
echo "Path: $($MyInvocation.MyCommand.Path)"
echo "Definition: $($MyInvocation.MyCommand.Definition)"
echo '*******************************'
echo ''
function myHelper()
{
echo '******** inside function scope'
#EMPTY
echo "Path: $($MyInvocation.MyCommand.Path)"
#Prints the string definition of the function itself
echo "Definition: $($MyInvocation.MyCommand.Definition)"
echo '******************************'
}
myHelper