function -

  显示原文与译文双语对照的内容

我开始使用powershell,'程序库'文件中创建函数来改善可读性,我从'员工'然后调用脚本。


=================== Library file ==========================
function ShowMessage($AValue)
{
 $a = new-object -comobject wscript.shell
 $b = $a.popup( $AValue )
}
=================== End Library file ==========================


=================== Worker file ==========================
. {c:scratchb.ps1}

ShowMessage"Hello"
=================== End Worker file ==========================

运行'员工'脚本在powershell的ide时没问题但是当我right-click职工文件并选择'使用PowerShell运行''衰减'不能找到该函数。 两个文件都位于同一个文件夹中。 这里发生了什么?

时间: 原作者:

尝试添加这样的脚本:


=================== Worker file ==========================
."c:scratchb.ps1"

ShowMessage"Hello"
=================== End Worker file ==========================

原作者:

在你的工作文件中,dot-source文件,这将加载所有内容( 函数。变量等) 到全局范围,然后你可以从库文件调用函数。


=================== Worker file ==========================
# dot-source library script
# notice that you need to have a space 
# between the dot and the path of the script
. c:library.ps1

ShowMessage -AValue Hello
=================== End Worker file ======================

原作者:
...