I have a PowerShell script whose purpose is to get a list of files then do some work on each file.
The list of files is generated by a recursive function like this:
function Recurse($path)
{
.. create $folder
foreach ($i in $folder.files) {
$i
}
foreach ($i in $folder.subfolders) {
Recurse($i.path)
}
}
Separate from this function i do a workflow that takes a list of files and do the work (in parallel) on each file. The code looks something like this:
workflow Do-Work {
param(
[parameter(mandatory)][object[]]$list
)
foreach -parallel ($f in $list) {
inlinescript {
.. do work on $Using:f
}
}
}
These two parts are then combined with the following logic:
$myList = Recurse($myPath)
Do-Work -list $myList
The problem is that this generates an error:
A workflow cannot use recursion.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : RecursiveWorkflowNotSupported
Why is this happening when the recursive function and the workflow is separate? Is there any way to work around this issue?
Recursive calling is not permitted in workflows.
Give your path directly:
Instead of this:
Recurse($myPath)
do this:
Recurse $myPath
You can refer to this article:
Adding Nested functions and Nested Workflows
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With