Powershell - 将两条管道合二为一

Powershell - Combine two pipelines into one

我正在使用 Powershell(版本 5.1.17763.1007),并希望将两个管道合二为一。 它们的内容非常相似; 他们递归地从文件夹中查找 Python 文件到它的子文件夹中, 并分别使用 Pylint 和 prospector 为这些 Python 文件生成 linting-reports (参见 https://www.pylint.org/ and https://pypi.org/project/prospector/

$path_to_files = "C:\Users$env:UserName\Desktop\my_project_folder\linter_reports"

# Get all Python modules in folder and generate Pylint reports
Get-ChildItem -Path $path_to_files -Recurse -Filter *.py |
  ForEach-Object { pylint $_.Name |
                   Out-File -FilePath "pylint_results_$($_.Name.TrimEnd(".py")).txt"
                   }

# Get all Python modules in folder and generate Prospector reports
Get-ChildItem -Path $path_to_files -Recurse -Filter *.py |
  ForEach-Object { prospector $_.Name |
                   Out-File -FilePath "prospector_results_$($_.Name.TrimEnd(".py")).txt"
                   }

我已经尝试过 Tee-Object Cmdlet (https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/tee-object?view=powershell-7),这是最好的方法吗? 我正在寻找这样的东西(伪代码):

Get-ChildItem -Path $path_to_files -Recurse -Filter *.py |
  ForEach-Object Tee-Object { pylint $_.Name |
                   Out-File -FilePath "pylint_results_$($_.Name.TrimEnd(".py")).txt"
                   } |
                            { prospector$_.Name |
                   Out-File -FilePath "prospector_results_$($_.Name.TrimEnd(".py")).txt"
                   }

为什么不依次执行这两个命令?

$path_to_files = "C:\Users$env:UserName\Desktop\my_project_folder\linter_reports"

# Get all Python modules in folder and generate Pylint and prospector reports
Get-ChildItem -Path $path_to_files -Recurse -Filter *.py |
  ForEach-Object { pylint $_.Name |
                   Out-File -FilePath "pylint_results_$($_.Name.TrimEnd(".py")).txt"

                   prospector $_.Name |
                   Out-File -FilePath "prospector_results_$($_.Name.TrimEnd(".py")).txt"
                   }