有人能告诉我为什么我不能在PowerShell脚本中调用函数吗?以下是我的代码:
Write-Host "Before calling Function."
testFunction
function testFunction()
{
Write-Host "Function has been called"
}
运行上述代码时,我收到以下错误信息:testFunction : 无法将“testFunction”识别为 cmdlet、function、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请验证路径是否正确,然后重试。 位于 C:\Users\andrew.short\Documents\Powershell\Backups\functionTest.ps1 的第 3 字符处 + testFunction + ~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (testFunction:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
我相信在同一个 PowerShell 脚本中调用函数肯定是可行的。请有人帮忙吗?