我想在文件 functions.ps1 中定义函数,然后从另一个脚本调用它。像这样:
函数.ps1:
Function Hi()
{
"hi"
}
从另一个脚本 (Call.ps1) 调用它。
调用.ps1:
invoke-expression -Command .\functions.ps1
Hi
但是函数是在脚本 functions.ps1 的局部范围内定义的,我得到错误:
The term 'hi' is not recognized as the name of a cmdlet, function,
script file , or operable program. Check the spelling of the name, or
if a path was included, v erify that the path is correct and try
again.
有没有简单的方法可以解决这个问题?
最佳答案
您必须dotsource您的脚本才能将其加载到您当前的运行空间:
. .\functions.ps1
Hi
关于function - 如何使公共(public)功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44042129/