在PowerShell中,如何在文件中定义函数并从PowerShell命令行调用它?
我有一个.ps1文件,我想在其中定义自定义函数。 想象一下该文件名为MyFunctions.ps1,内容如下: Write-Host "Installing functions" function A1 { Write-Host "A1 is running!" } Write-Host "Done" 要运行此脚本并从理论上注册A1函数,我导航到.ps1文件所在的文件夹并运行该文件: .\MyFunctions.ps1 输出: Installing functions Done 但是,当我尝试调用A1时,我只是得到了错误,指出该名称没有命令/函数: The term 'A1' 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 …