I have a PowerShell script that is running many msdeploy concurrently on multiple remote servers using Powershell Workflow.
Everything works fine except that at the end of each "Foreach -Parallel" loop, I get this exception:
Microsoft.PowerShell.Utility\Write-Error : The workflow was terminated by a Terminate activity.
At Execute-Bootstrapper:28 char:28
+
+ CategoryInfo : NotSpecified: (:) [Write-Error], WorkflowReturnException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Workflow.WorkflowReturnException,Microsoft.PowerShell.Commands.Writ
eErrorCommand
+ PSComputerName : [localhost]
How can I fix this ? Is there a specific way to end a workflow ?
Here is the part related to the parallel execution :
foreach -Parallel ($remoteHost in $selectedHosts) {
if($Env:FULL -eq "true") {
$process = Start-Process -PassThru -Wait -NoNewWindow "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" "xxx --full"
} else {
$process = Start-Process -PassThru -Wait -NoNewWindow "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" "xxx"
}
if($process.ExitCode -ne 0) {
Exit $process.ExitCode
}
}
Thank you.
Source: Workflows: The Basics (under Jobs and Workflows main article at Hey, Scripting Guy! Blog).
The following partially commented script could help. Tested using very simple parameters passed to
MSDeploy.exe
such that-help -verb
is valid, exit code = 0 while other-help -brew
and-help -bubu
aren't, exit code = -1.-NoNewWindow
without-RedirectStandardOutput
and-RedirectStandardError
would raise following error (consider omitting the-NoNewWindow
parameter at all):Above workflow returns an array of hash-tables (roughly
hostname: exitcode
pairs) because a bare exit code would not suffice as the output order is random since it was run in parallel.Output: