问题描述
我在库"文件中具有要从工作人员"脚本中调用的功能.
I have functions in a 'library' file to be called from my 'worker' script.
库文件
function ShowMessage($AValue)
{
$a = new-object -comobject wscript.shell
$b = $a.popup( $AValue )
}
工作文件
. {c:\scratch\b.ps1}
ShowMessage "Hello"
在PowerShell IDE中运行'worker'脚本可以正常工作,但是当我右键单击worker文件并选择'Run with PowerShell'时,找不到函数'ShowMessage'.这两个文件都在同一个文件夹中.可能会发生什么?
Running the 'worker' script works fine when in the PowerShell IDE but when I right-click the worker file and choose 'Run with PowerShell' it cannot find the function 'ShowMessage'. Both files are in the same folder. What might be happening?
推荐答案
在工作文件中更改为:
. "c:\scratch\b.ps1"
ShowMessage "Hello"
如下面的@RoiDanton所述:
As @RoiDanton mentioned below:
第一个点是用于修改范围的运算符,在这种情况下,它与路径无关.请参见点源符号.
The first dot is an operator used to modify the scope and in that context it has nothing to do with paths. See Dot Source Notation.
这篇关于使用“使用PowerShell运行"执行时,在另一个脚本中调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!