1

I'm using Azure Devops Pipelines

Pipeline calls a powershell script that has a function inside of it.

I make a database call to get some data about a client that will get updated.

I loop the clients and call the function to do the actual updating of the client (updating db, updating code, other things)


$Function = Get-Command runUpdate
$clientList| ForEach-Object -ThrottleLimit 5 -Parallel {
        $client = $_
        write-host "##[section]starting: $client"
        $refObj = $using:Function
        [System.Threading.Monitor]::Enter($refObj)
        ${function:runUpdate} = $using:Function
        runUpdate -client $client -version $($using:prVersion) -packagePath $($using:packagePath)
        write-host "##[section]finished: $client"
        [System.Threading.Monitor]::Exit($refObj)
}

It will work fine most of the time, but then while inside of the runUpdate function I'll get errors such as

The term 'write-host' is not recognized as a name of a cmdlet, function, script file, or executable program.
The term 'Test-Path' is not recognized as a name of a cmdlet, function, script file, or executable program.
The term 'Add-Content' is not recognized as a name of a cmdlet, function, script file, or executable program.

I used to have the function within a job and it seems to work more consistently without errors, I swapped it over to threaded jobs so it could actually write out the output so it didn't appear as a mystery function that was being invoked.

Is there some other way I should be calling the function? Is there a reason that powershell would have issues with basic commands like Write-Host?

Josh Knutson
  • 325
  • 1
  • 5
  • 11

0 Answers0