I have a pipeline task which is as follow:
- task: PowerShell@2
displayName: 'Script1'
inputs:
filePath: '$(System.DefaultWorkingDirectory)/Terraform/helloworld1.ps1'
And it run a helloworld1.ps1 , but the helloworld1.ps1 script call another script. here's the code of helloworld1:
& "$PSScriptRoot/helloworld2.ps1"
Write-Host 'Hello from 1st File.'
printHello
And the helloworld2.ps1 scripts contains this one line only:
function printHello()
{
Write-Host 'Hello from 2nd File.'
}
BUT, when when pipelines triggers, its run the Helloworld1.ps1 and print its 2nd line and then failed on 3rd line throwing the error:
| The term 'PrintHello' is not recognized as a name of a
| cmdlet, function, script file, or executable program. Check
| the spelling of the name, or if a path was included, verify
| that the path is correct and try again.


& .\somescript.ps1) runs a script in a child scope which means that any variables and functions defined inside the script are only available inside that script. If you want functions to still be available after the child script has finished you can use the Dot Sourcing Operator (e.g.. .\somescript.ps1) instead - see learn.microsoft.com/en-us/powershell/module/…