【发布时间】:2010-09-29 20:49:19
【问题描述】:
以下 S.O. question 解决了问题(当您尝试从脚本中解决问题时)。 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
【问题讨论】:
标签: powershell